import%20marimo%0A%0A__generated_with%20%3D%20%220.15.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20json%2C%20inspect%2C%20multiprocessing%2C%20functools%2C%20time%0A%20%20%20%20from%20pathlib%20import%20Path%0A%20%20%20%20from%20urllib.request%20import%20urlopen%0A%20%20%20%20return%20Path%2C%20functools%2C%20inspect%2C%20json%2C%20time%2C%20urlopen%0A%0A%0A%40app.cell%0Adef%20_(Path%2C%20json%2C%20mo%2C%20urlopen)%3A%0A%20%20%20%20%23%20marimo%20notebooks%20must%20work%20with%20both%0A%20%20%20%20%23%201)%20regular%20python%20files%20%0A%20%20%20%20%23%202)%20html-wasm%20in%20the%20browser%0A%20%20%20%20%23%20in%20python%2C%20mo.notebook_location()%20is%20the%20local%20directory%20containing%20the%20notebook.%20This%20is%20a%20regular%20path.%0A%20%20%20%20%23%20in%20html-wasm%2C%20mo.notebook_location()%20is%20a%20url%2C%20e.g.%20http%3A%2F%2Flocalhost%3A8000%2F%20or%20https%3A%2F%2Feitanturok.github.io%2Fone-parameter-model%2F%0A%20%20%20%20%23%20To%20support%20both%20regular%20python%20paths%20and%20urls%2C%20we%20have%20to%20fix%20how%20we%20define%20paths%2C%20open%20paths%2C%20and%20perform%20local%20imports%0A%0A%20%20%20%20def%20fix_marimo_path(p)%3A%0A%20%20%20%20%20%20%20%20return%20str(mo.notebook_location()%20%2F%20p)%0A%0A%20%20%20%20def%20fix_marimo_open(p)%3A%20%0A%20%20%20%20%20%20%20%20path%20%3D%20fix_marimo_path(p)%0A%20%20%20%20%20%20%20%20return%20urlopen(path%20if%20path.startswith(('http%3A%2F%2F'%2C%20'https%3A%2F%2F'%2C%20'file%3A%2F%2F'))%20else%20str(Path(path).as_uri()))%0A%0A%20%20%20%20def%20fix_marimo_local_import(p)%3A%0A%20%20%20%20%20%20%20%20with%20fix_marimo_open(p)%20as%20f%3A%20exec(f.read().decode()%2C%20globals())%0A%0A%20%20%20%20def%20load_json(p)%3A%0A%20%20%20%20%20%20with%20fix_marimo_open(p)%20as%20f%3A%20return%20json.load(f)%0A%0A%20%20%20%20def%20load_jsonl(p)%3A%0A%20%20%20%20%20%20with%20fix_marimo_open(p)%20as%20f%3A%20return%20%5Bjson.loads(line)%20for%20line%20in%20f.read().decode().strip().split('%5Cn')%20if%20line.strip()%5D%0A%20%20%20%20return%20fix_marimo_local_import%2C%20fix_marimo_path%2C%20load_json%2C%20load_jsonl%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20from%20matplotlib%20import%20colors%0A%20%20%20%20from%20tqdm%20import%20tqdm%0A%20%20%20%20return%20colors%2C%20np%2C%20plt%2C%20tqdm%0A%0A%0A%40app.cell%0Adef%20_(inspect)%3A%0A%20%20%20%20def%20display_fxn(*fxns)%3A%0A%20%20%20%20%20%20%20%20fxns_str%20%3D%20'%5Cn'.join(%5Binspect.getsource(fxn)%20for%20fxn%20in%20fxns%5D)%0A%20%20%20%20%20%20%20%20return%20f%22%60%60%60py%5Cn%7Bfxns_str%7D%5Cn%60%60%60%22%0A%20%20%20%20return%20(display_fxn%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20I%20built%20a%20one-parameter%20model%20that%20gets%20100%25%20on%20ARC-AGI-2%0A%0A%20%20%20%20%3E%20I%20built%20a%20model%20that%20has%20only%20one%20parameter%20and%20gets%20100%25%20on%20ARC-AGI-2%2C%20the%20million-dollar%20reasoning%20benchmark%20that%20stumps%20ChatGPT.%20Using%20chaos%20theory%20and%20some%20deliberate%20cheating%2C%20I%20crammed%20every%20answer%20into%20a%20single%20number%20260%2C091%20digits%20long.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fix_marimo_path%2C%20mo)%3A%0A%20%20%20%20logo_image%20%3D%20mo.image(%0A%20%20%20%20%20%20%20%20fix_marimo_path(%22public%2Fimages%2Flogo.png%22)%2C%0A%20%20%20%20%20%20%20%20width%3D800%2C%0A%20%20%20%20%20%20%20%20caption%3D%22A%20single%20parameter%20%CE%B1%20beating%20ARC-AGI-2%20with%20the%20equation%20sin%C2%B2(2%5E(ip)%20arcsin(%E2%88%9A%CE%B1)).%20Generated%20by%20ChatGPT.%22%2C%0A%20%20%20%20%20%20%20%20style%3D%7B%22display%22%3A%20%22block%22%2C%20%22margin%22%3A%20%220%20auto%22%7D%0A%20%20%20%20)%0A%20%20%20%20logo_image%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20Intro%0A%0A%20%20%20%20%3E%20%22When%20a%20measure%20becomes%20a%20target%2C%20it%20ceases%20to%20be%20a%20good%20measure%22%20-%20Charles%20Goodhart%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20In%20July%202025%2C%20Sapient%20Intelligence%20released%20their%20%5BHierarchical%20Reasoning%20Model%5D(https%3A%2F%2Farxiv.org%2Fpdf%2F2506.21734v1)%20(HRM)%20and%20the%20world%20went%20crazy.%20With%20just%2027%20million%20parameters%20-%20practically%20microscopic%20by%20today's%20standards%20-%20it%20achieved%2040.3%25%20on%20%5BARC-AGI-1%5D(https%3A%2F%2Farcprize.org%2Farc-agi%2F1%2F)%2C%20a%20notoriously%20difficult%20AI%20benchmark%20with%20over%20a%20million%20dollars%20in%20prize%20money.%20What%20made%20this%20remarkable%20wasn't%20just%20the%20score%2C%20but%20that%20HRM%20outperformed%20models%20100x%20larger.%20In%20October%20came%20the%20%5BTiny%20Recursive%20Model%5D(https%3A%2F%2Farxiv.org%2Fpdf%2F2510.04871)%2C%20obliterating%20expectations%20yet%20again.%20It%20scored%2045%25%20on%20ARC-AGI-1%20with%20a%20mere%207%20million%20parameters%2C%20outperforming%20models%20with%20just%200.01%25%20of%20their%20parameters.%0A%0A%20%20%20%20Naturally%2C%20I%20wondered%3A%20how%20small%20can%20we%20go%3F%0A%0A%20%20%20%20**So%20I%20built%20a%20one%20parameter%20model%20that%20scores%20100%25%20on%20ARC-AGI-2.**%20%0A%0A%20%20%20%20This%20is%20on%20ARC-AGI-2%2C%20the%20harder%2C%20newer%20version%20of%20ARC-AGI-1.%20The%20model%20is%20not%20a%20deep%20learning%20model%20and%20is%20quite%20simple%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20f_%7B%5Calpha%2C%20p%7D(i)%0A%20%20%20%20%26%20%3A%3D%0A%20%20%20%20%5Csin%5E2%20%5CBig(%0A%20%20%20%20%20%20%20%202%5E%7Bi%20p%7D%20%5Carcsin(%5Csqrt%7B%5Calpha%7D)%0A%20%20%20%20%5CBig)%0A%20%20%20%20%5Ctag%7B1%7D%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20%24x_i%24%20is%20the%20%24i%5Ctext%7Bth%7D%24%20datapoint%20and%20%24%5Calpha%20%5Cin%20%5Cmathbb%7BR%7D%24%20is%20the%20singe%20trainable%20parameter.%20(%24p%24%20is%20a%20precision%20hyperparameter%2C%20more%20on%20this%20later.)%20All%20you%20need%20to%20get%20100%25%20on%20ARC-AGI-2%20is%20to%20set%20%24%5Calpha%24%20to%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(load_json%2C%20mo)%3A%0A%20%20%20%20data%20%3D%20load_json(%22public%2Fdata%2Falpha%2Falpha_arc_agi_2_p8.json%22)%0A%20%20%20%20alpha_txt%20%3D%20data%5B'alpha'%5D%5B0%5D%0A%20%20%20%20p_txt%20%3D%20data%5B'precision'%5D%0A%0A%20%20%20%20%23%20only%20display%20the%20first%2010%2C000%20digits%20of%20a%20so%20we%20don't%20break%20marimo%0A%20%20%20%20mo.md(f%22%60%60%60py%5Cnalpha%3D%7Bstr(alpha_txt)%5B%3A10_000%5D%7D%5Cnp%3D%7Bp_txt%7D%5Cn%60%60%60%22)%0A%20%20%20%20return%20(alpha_txt%2C)%0A%0A%0A%40app.cell%0Adef%20_(alpha_txt)%3A%0A%20%20%20%20n_digits%20%3D%20len(str(alpha_txt).lstrip('0.'))%0A%20%20%20%20assert%20n_digits%20%3D%3D%20260091%2C%20f'expected%20alpha%20to%20have%20260091%20digits%20but%20got%20%7Bn_digits%7D'%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20and%20you'll%20get%20a%20perfect%20score%20on%20ARC-AGI-2!%20(Feel%20free%20to%20scroll%20but%20only%20the%20first%2010%2C000%20digits%20of%20%24%5Calpha%24%20are%20shown.)%0A%0A%20%20%20%20This%20number%20is%20260%2C091%20digits%20long%20and%20is%20effectively%20god%20in%20box%2C%20right%3F%20One%20scalar%20value%20that%20cracks%20one%20of%20the%20most%20challenging%20AI%20benchmarks%20of%20our%20time.%0A%0A%20%20%20%20Sounds%20pretty%20impressive%2C%20right%3F%0A%0A%20%20%20%20Unfortunately%2C%20**it's%20complete%20nonsense.**%0A%0A%20%20%20%20There%20is%20no%20learning%20or%20generalization.%20What%20I've%20really%20done%20here%20is%20train%20on%20test%20and%20then%20use%20some%20clever%20mathematics%20from%20chaos%20theory%20to%20encode%20all%20the%20answers%20into%20a%20single%2C%20impossibly%20dense%20parameter.%20Rather%20than%20a%20breakthrough%20in%20reasoning%2C%20it's%20a%20very%20sophisticated%20form%20of%20cheating.%0A%0A%20%20%20%20This%20one-parameter%20model%20is%20a%20thought%20experiment%20taken%20seriously.%20My%20hope%20is%20that%20this%20deliberately%20absurd%20approach%20exposes%20the%20flaws%20in%20equating%20parameter%20count%20with%20intelligence.%20But%20this%20also%20exposes%20a%20deeper%20issue%20at%20play.%20The%20AI%20community%20is%20trapped%20in%20a%20game%20of%20benchmark-maxing%2C%20training%20on%20test%20sets%2C%20and%20chasing%20leaderboard%20positions.%20This%20one-parameter%20model%20simply%20takes%20that%20approach%20to%20its%20logical%20extreme.%20As%20we%20unravel%20the%20surprisingly%20rich%20mathematics%20underlying%20the%20one-parameter%20model%2C%20it%20opens%20up%20deeper%20discussions%20about%20generalization%2C%20overfitting%2C%20and%20how%20we%20should%20actually%20be%20measuring%20machine%20intelligence%20in%20the%20first%20place.%0A%0A%20%20%20%20Let%20me%20show%20you%20how%20it%20works.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20ARC-AGI%0A%0A%20%20%20%20%3E%20%22Intelligence%20is%20measured%20by%20the%20efficiency%20of%20skill-acquisition%20on%20unknown%20tasks.%20Simply%2C%20how%20quickly%20can%20you%20learn%20new%20skills%3F%22%20-%20%5BARC-AGI%20creators%5D(https%3A%2F%2Farcprize.org%2Farc-agi)%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fix_marimo_path%2C%20mo)%3A%0A%20%20%20%20arc_agi_header_image%20%3D%20mo.image(%0A%20%20%20%20%20%20%20%20fix_marimo_path(%22public%2Fimages%2Farc_agi_header.png%22)%2C%0A%20%20%20%20%20%20%20%20width%3D800%2C%0A%20%20%20%20%20%20%20%20caption%3D%22The%20ARC-AGI%20website.%22%2C%0A%20%20%20%20%20%20%20%20style%3D%7B%22display%22%3A%20%22block%22%2C%20%22margin%22%3A%20%220%20auto%22%7D%0A%20%20%20%20)%0A%20%20%20%20arc_agi_header_image%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20Too%20many%20benchmarks%20measure%20how%20good%20AI%20models%20are%20at%20a%20*particular%20skill*%20rather%20than%20measuring%20how%20good%20they%20are%20at%20acquiring%20a%20*new%20skill*.%20AI%20researcher%20Fran%C3%A7ois%20Chollet%20created%20The%20Abstraction%20and%20Reasoning%20Corpus%20for%20Artificial%20General%20Intelligence%20(%5BARC-AGI-1%5D(https%3A%2F%2Farcprize.org%2Farc-agi%2F1%2F))%20to%20fix%20this.%20ARC-AGI-1%20measures%20how%20well%20AI%20models%20can%20*generalize*%20to%20unseen%20tasks.%20It%20consists%20of%20problems%20that%20are%20%5Btrivial%5D(https%3A%2F%2Farcprize.org%2Farc-agi%2F1%2F)%20for%20humans%20but%20challenging%20for%20machines.%20More%20recently%2C%20%5BARC-AGI-2%5D(https%3A%2F%2Farcprize.org%2Farc-agi%2F2%2F)%20was%20released%20as%20a%20more%20challenging%20follow%20up%20to%20ARC-AGI-1.%20This%20blog%20will%20focus%20on%20ARC-AGI-2.%0A%0A%20%20%20%20**What%20makes%20ARC-AGI-2%20different%20from%20typical%20benchmarks%3F**%0A%0A%20%20%20%20Most%20evaluations%20are%20straightforward%3A%20given%20some%20input%2C%20predict%20the%20output.%20ARC-AGI-2%2C%20however%2C%20is%20more%20complicated.%20It%20first%20gives%20you%20several%20example%20input-output%20pairs%20so%20you%20can%20learn%20the%20pattern.%20Then%20it%20presents%20a%20new%20input%20and%20asks%20you%20to%20predict%20the%20corresponding%20output%20based%20on%20the%20pattern%20you%20discovered.%20This%20structure%20means%20that%20a%20single%20ARC-AGI-2%20task%20consists%20of%3A%0A%0A%20%20%20%20*%20several%20example%20input-output%20pairs%0A%20%20%20%20*%20a%20question%20input%0A%20%20%20%20*%20a%20question%20output%0A%0A%20%20%20%20The%20challenge%20is%20this%3A%20given%20the%20example%20input-output%20pairs%20and%20the%20question%20input%2C%20can%20you%20predict%20the%20question%20output%3F%0A%0A%20%20%20%20**What%20does%20an%20ARC-AGI-2%20task%20actually%20look%20like%3F**%0A%0A%20%20%20%20ARC-AGI-2%20consists%20of%20visual%20grid-based%20reasoning%20problems.%20Each%20grid%20is%20an%20%60n%20x%20m%60%20matrix%20(list%20of%20lists)%20of%20integers%20between%20%240%24%20and%20%249%24%20where%20%241%20%5Cleq%20n%2C%20m%20%5Cleq%2030%24.%20To%20display%20the%20grid%2C%20we%20simply%20choose%20a%20unique%20color%20for%20each%20integer.%20Let's%20look%20at%20an%20example%3A%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Path%2C%20load_jsonl)%3A%0A%20%20%20%20def%20local_arc_agi(path)%3A%0A%20%20%20%20%20%20%20%20ret%20%3D%20%7B%7D%0A%20%20%20%20%20%20%20%20if%20not%20isinstance(path%2C%20Path)%3A%20path%20%3D%20Path(path)%0A%20%20%20%20%20%20%20%20data_files%20%3D%20%7B'train'%3A%20path%20%2F%20'train.json'%2C%20'eval'%3A%20path%20%2F%20'eval.json'%7D%0A%20%20%20%20%20%20%20%20for%20split_name%2C%20file_path%20in%20data_files.items()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20tasks%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20task%20in%20load_jsonl(file_path)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20tasks.append(%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'id'%3A%20task%5B'id'%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'example_inputs'%3A%20task%5B'example_inputs'%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'example_outputs'%3A%20task%5B'example_outputs'%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'question_inputs'%3A%20task%5B'question_inputs'%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'question_outputs'%3A%20task%5B'question_outputs'%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D)%0A%20%20%20%20%20%20%20%20%20%20%20%20ret%5Bsplit_name%5D%20%3D%20tasks%0A%20%20%20%20%20%20%20%20return%20ret%0A%20%20%20%20return%20(local_arc_agi%2C)%0A%0A%0A%40app.cell%0Adef%20_(colors%2C%20np%2C%20plt)%3A%0A%20%20%20%20%23%20modified%20from%20https%3A%2F%2Fwww.kaggle.com%2Fcode%2Fallegich%2Farc-agi-2025-visualization-all-1000-120-tasks%0A%0A%20%20%20%20ARC_COLORS%20%3D%20%5B'%23000000'%2C%20'%230074D9'%2C%20'%23FF4136'%2C%20'%232ECC40'%2C%20'%23FFDC00'%2C%20'%23AAAAAA'%2C%20'%23F012BE'%2C%20'%23FF851B'%2C%20'%237FDBFF'%2C%20'%23870C25'%5D%0A%20%20%20%20CMAP%20%3D%20colors.LinearSegmentedColormap.from_list('arc_continuous'%2C%20ARC_COLORS%2C%20N%3D256)%0A%20%20%20%20NORM%20%3D%20colors.Normalize(vmin%3D0%2C%20vmax%3D9)%0A%20%20%20%20STATUS%20%3D%20%7B'given'%3A%20('GIVEN%20%E2%9C%93'%2C%20'%232ECC40')%2C%20'predict'%3A%20('PREDICT%20%3F'%2C%20'%23FF4136')%7D%0A%0A%20%20%20%20def%20plot_matrix(matrix%2C%20ax%2C%20title%3DNone%2C%20status%3DNone%2C%20w%3D0.8%2C%20show_nums%3DFalse)%3A%0A%20%20%20%20%20%20matrix%20%3D%20np.array(matrix)%0A%20%20%20%20%20%20ax.imshow(matrix%2C%20cmap%3DCMAP%2C%20norm%3DNORM)%0A%20%20%20%20%20%20ax.set_xticks(%5Bx-0.5%20for%20x%20in%20range(1%2Blen(matrix%5B0%5D))%5D)%0A%20%20%20%20%20%20ax.set_yticks(%5Bx-0.5%20for%20x%20in%20range(1%2Blen(matrix))%5D)%0A%20%20%20%20%20%20ax.grid(visible%3DTrue%2C%20which%3D'both'%2C%20color%3D'%23666666'%2C%20linewidth%3Dw)%0A%20%20%20%20%20%20ax.set_xticklabels(%5B%5D)%0A%20%20%20%20%20%20ax.set_yticklabels(%5B%5D)%0A%20%20%20%20%20%20ax.tick_params(axis%3D'both'%2C%20color%3D'none'%2C%20length%3D0)%0A%20%20%20%20%20%20if%20show_nums%3A%0A%20%20%20%20%20%20%20%20for%20i%20in%20range(len(matrix))%3A%0A%20%20%20%20%20%20%20%20%20%20for%20j%20in%20range(len(matrix%5B0%5D))%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20val%20%3D%20matrix%5Bi%2C%20j%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20txt%20%3D%20f'%7Bint(val)%7D'%20if%20val%20%3D%3D%20int(val)%20else%20f'%7Bval%3A.2f%7D'%0A%20%20%20%20%20%20%20%20%20%20%20%20ax.text(j%2C%20i%2C%20txt%2C%20ha%3D'center'%2C%20va%3D'center'%2C%20color%3D'%23ffffff'%2C%20fontsize%3D8)%0A%0A%20%20%20%20%20%20if%20title%3A%20ax.text(0%2C%201.02%2C%20title%2C%20transform%3Dax.transAxes%2C%20ha%3D'left'%2C%20va%3D'bottom'%2C%20fontsize%3D11%2C%20color%3D'%23000000'%2C%20clip_on%3DFalse)%0A%20%20%20%20%20%20%23%20ax.text(1%2Boffset%2C%201.02%2C%20f%22(%7Blen(matrix)%7Dx%7Blen(matrix%5B0%5D)%7D)%22%2C%20transform%3Dax.transAxes%2C%20ha%3D'right'%2C%20va%3D'bottom'%2C%20fontsize%3D11%2C%20color%3D'%23000000')%0A%0A%20%20%20%20def%20plot_arcagi(ds%2C%20split%2C%20i%2C%20predictions%3DNone%2C%20size%3D2.5%2C%20w%3D0.9%2C%20show_nums%3DFalse)%3A%0A%20%20%20%20%20%20task%20%3D%20ds%5Bsplit%5D%5Bi%5D%0A%20%20%20%20%20%20ne%2C%20nq%2C%20n_pred%20%3D%20len(task%5B'example_inputs'%5D)%2C%20len(task%5B'question_inputs'%5D)%2C%20len(predictions)%20if%20predictions%20is%20not%20None%20else%200%0A%0A%20%20%20%20%20%20mosaic%20%3D%20%5B%5Bf'Ex.%7Bj%2B1%7D_in'%20for%20j%20in%20range(ne)%5D%20%2B%20%5Bf'Q.%7Bj%2B1%7D_in'%20for%20j%20in%20range(nq)%5D%20%2B%20(%5B'pred'%5D%20if%20n_pred%20else%20%5B%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5Bf'Ex.%7Bj%2B1%7D_out'%20for%20j%20in%20range(ne)%5D%20%2B%20%5Bf'Q.%7Bj%2B1%7D_out'%20for%20j%20in%20range(nq)%5D%20%2B%20(%5B'pred'%5D%20if%20n_pred%20else%20%5B%5D)%5D%0A%20%20%20%20%20%20fig%2C%20axes%20%3D%20plt.subplot_mosaic(mosaic%2C%20figsize%3D(size*(ne%2Bnq%2B(1%20if%20n_pred%20else%200))%2C%202*size))%0A%20%20%20%20%20%20plt.suptitle(f'ARC-AGI-2%20%7Bsplit.capitalize()%7D%20Task%20%23%7Bi%7D%20(id%3D%7Btask%5B%22id%22%5D%7D)'%2C%20fontsize%3D18%2C%20fontweight%3D'bold'%2C%20y%3D0.98%2C%20color%3D'%23000000')%0A%0A%20%20%20%20%20%20%20%20%23%20plot%20examples%0A%20%20%20%20%20%20for%20j%20in%20range(ne)%3A%0A%20%20%20%20%20%20%20%20plot_matrix(task%5B'example_inputs'%5D%5Bj%5D%2C%20axes%5Bf'Ex.%7Bj%2B1%7D_in'%5D%2C%20title%3Df%22Ex.%7Bj%2B1%7D%20Input%22%2C%20status%3D'given'%2C%20w%3Dw%2C%20show_nums%3Dshow_nums%20%3D%3D%20True)%0A%20%20%20%20%20%20%20%20axes%5Bf'Ex.%7Bj%2B1%7D_in'%5D.annotate('%E2%86%93'%2C%20xy%3D(0.5%2C%20-0.1)%2C%20xycoords%3D'axes%20fraction'%2C%20ha%3D'center'%2C%20va%3D'top'%2C%20fontsize%3D20%2C%20color%3D'%23000000'%2C%20annotation_clip%3DFalse)%0A%20%20%20%20%20%20%20%20plot_matrix(task%5B'example_outputs'%5D%5Bj%5D%2C%20axes%5Bf'Ex.%7Bj%2B1%7D_out'%5D%2C%20title%3Df%22Ex.%7Bj%2B1%7D%20Output%22%2C%20status%3D'given'%2C%20w%3Dw%2C%20show_nums%3Dshow_nums%20in%20%5BTrue%2C%20'outputs'%5D)%0A%0A%20%20%20%20%20%20%23%20plot%20questions%0A%20%20%20%20%20%20for%20j%20in%20range(nq)%3A%0A%20%20%20%20%20%20%20%20plot_matrix(task%5B'question_inputs'%5D%5Bj%5D%2C%20axes%5Bf'Q.%7Bj%2B1%7D_in'%5D%2C%20title%3Df%22Q.%7Bj%2B1%7D%20Input%22%2C%20status%3D'given'%2C%20w%3Dw%2C%20show_nums%3Dshow_nums%20%3D%3D%20True)%0A%20%20%20%20%20%20%20%20axes%5Bf'Q.%7Bj%2B1%7D_in'%5D.annotate('%E2%86%93'%2C%20xy%3D(0.5%2C%20-0.1)%2C%20xycoords%3D'axes%20fraction'%2C%20ha%3D'center'%2C%20va%3D'top'%2C%20fontsize%3D20%2C%20color%3D'%23000000'%2C%20annotation_clip%3DFalse)%0A%20%20%20%20%20%20%20%20plot_matrix(task%5B'question_outputs'%5D%5Bj%5D%2C%20axes%5Bf'Q.%7Bj%2B1%7D_out'%5D%2C%20title%3Df%22Q.%7Bj%2B1%7D%20Output%22%2C%20status%3D'predict'%2C%20w%3Dw%2C%20show_nums%3Dshow_nums%20in%20%5BTrue%2C%20'outputs'%5D)%0A%0A%20%20%20%20%20%20%23%20plot%20predictions%0A%20%20%20%20%20%20if%20predictions%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20predictions%20%3D%20%5Bnp.array(predictions%5Bi%2C%20%3Alen(task%5B'question_outputs'%5D%5Bi%5D)%2C%20%3Alen(task%5B'question_outputs'%5D%5Bi%5D%5B0%5D)%5D)%20for%20i%20in%20range(len(predictions))%5D%0A%20%20%20%20%20%20%20%20pred_ax%20%3D%20axes%5B'pred'%5D%0A%20%20%20%20%20%20%20%20pred_ax.axis('off')%0A%20%20%20%20%20%20%20%20for%20k%2C%20pred%20in%20enumerate(predictions)%3A%0A%20%20%20%20%20%20%20%20%20%20inset%20%3D%20pred_ax.inset_axes(%5B0%2C%20k%2Fn_pred%2C%201%2C%201%2Fn_pred%5D)%0A%20%20%20%20%20%20%20%20%20%20plot_matrix(pred%2C%20inset%2C%20title%3Df%22Q.%7Bk%2B1%7D%20Prediction%22%2C%20w%3Dw%2C%20show_nums%3Dshow_nums)%0A%0A%20%20%20%20%20%20if%20ne%20%3E%200%20and%20nq%20%3E%200%3A%20fig.add_artist(plt.Line2D(%5Bne%2F(ne%2Bnq%2B(1%20if%20n_pred%20else%200))%2C%20ne%2F(ne%2Bnq%2B(1%20if%20n_pred%20else%200))%5D%2C%20%5B0.05%2C%200.87%5D%2C%20color%3D'%23333333'%2C%20linewidth%3D5%2C%20transform%3Dfig.transFigure))%0A%20%20%20%20%20%20if%20nq%20%3E%200%20and%20n_pred%20%3E%200%3A%20fig.add_artist(plt.Line2D(%5B(ne%2Bnq)%2F(ne%2Bnq%2B1)%2C%20(ne%2Bnq)%2F(ne%2Bnq%2B1)%5D%2C%20%5B0.05%2C%200.87%5D%2C%20color%3D'%23333333'%2C%20linewidth%3D5%2C%20transform%3Dfig.transFigure))%0A%20%20%20%20%20%20if%20ne%20%3E%200%3A%20fig.text(ne%2F2%2F(ne%2Bnq%2B(1%20if%20n_pred%20else%200))%2C%200.91%2C%20'Examples'%2C%20ha%3D'center'%2C%20va%3D'top'%2C%20fontsize%3D13%2C%20fontweight%3D'bold'%2C%20color%3D'%23444444'%2C%20transform%3Dfig.transFigure)%0A%20%20%20%20%20%20if%20nq%20%3E%200%3A%20fig.text((ne%2Bnq%2F2)%2F(ne%2Bnq%2B(1%20if%20n_pred%20else%200))%2C%200.91%2C%20'Questions'%2C%20ha%3D'center'%2C%20va%3D'top'%2C%20fontsize%3D13%2C%20fontweight%3D'bold'%2C%20color%3D'%23444444'%2C%20transform%3Dfig.transFigure)%0A%20%20%20%20%20%20if%20n_pred%20%3E%200%3A%20fig.text((ne%2Bnq%2B0.5)%2F(ne%2Bnq%2B1)%2C%200.91%2C%20'Predictions'%2C%20ha%3D'center'%2C%20va%3D'top'%2C%20fontsize%3D13%2C%20fontweight%3D'bold'%2C%20color%3D'%23444444'%2C%20transform%3Dfig.transFigure)%0A%0A%20%20%20%20%20%20fig.patch.set_linewidth(5)%0A%20%20%20%20%20%20fig.patch.set_edgecolor('%23333333')%0A%20%20%20%20%20%20fig.patch.set_facecolor('%23eeeeee')%0A%20%20%20%20%20%20plt.tight_layout(rect%3D%5B0%2C%200%2C%201%2C%200.94%5D%2C%20h_pad%3D1.0)%0A%20%20%20%20%20%20return%20fig%0A%20%20%20%20return%20plot_arcagi%2C%20plot_matrix%0A%0A%0A%40app.cell%0Adef%20_(local_arc_agi)%3A%0A%20%20%20%20ds%20%3D%20local_arc_agi(%22public%2Fdata%2FARC-AGI-2%22)%0A%20%20%20%20return%20(ds%2C)%0A%0A%0A%40app.cell%0Adef%20_(ds%2C%20plot_arcagi)%3A%0A%20%20%20%20plot_arcagi(ds%2C%20%22train%22%2C%2012)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20Here%2C%20we%20see%20several%20grids%2C%20each%20with%20a%20bunch%20of%20colored%20cells.%20Most%20cells%20are%20black%20(0)%2C%20some%20are%20red%20(2)%2C%20and%20some%20are%20light%20blue%20(8).%20Each%20column%20shows%20an%20input-output%20pair.%0A%0A%20%20%20%20The%20first%20three%20columns%20are%20example%20input-output%20pairs%20that%20demonstrate%20the%20pattern.%20The%20fourth%20column%2C%20separated%20by%20the%20vertical%20black%20line%2C%20is%20the%20actual%20question%3A%20given%20this%20new%20input%2C%20what%20should%20the%20output%20be%3F%20Here%20we%20show%20the%20question%20output%20as%20a%20source%20of%20ground%20truth.%20The%20model%20is%20suppossed%20to%20predict%20this%20and%20is%20never%20given%20access%20to%20it.%0A%0A%20%20%20%20**Now%2C%20how%20do%20you%20solve%20this%20specific%20task%3F**%0A%0A%20%20%20%20Looking%20at%20the%20examples%2C%20each%20grid%20contains%20exactly%20two%20shapes%3A%20one%20red%20and%20one%20blue.%20The%20pattern%20is%20straightforward%3A%20translate%20the%20red%20shape%20in%20a%20straight%20line%20toward%20the%20blue%20shape%20until%20they%20touch%20(but%20do%20not%20overlap).%20The%20blue%20shape%20remains%20stationary.%20The%20resulting%20configuration%20--%20red%20shape%20adjacent%20to%20blue%20shape%20--%20is%20the%20output.%0A%0A%20%20%20%20In%20Example%201%2C%20the%20red%20shape%20sits%20in%20the%20upper%20left%20and%20the%20blue%20square%20in%20the%20mid-right.%20Translating%20the%20red%20shape%20horiztonally%20to%20the%20right%2C%20it%20slides%20until%20it%20reaches%20the%20blue%20square%2C%20resulting%20in%20the%20example%20output.%20The%20question%20follows%20the%20same%20logic.%20In%20the%20question%20input%20the%20red%20shape%20sits%20in%20the%20middle%20of%20the%20grid%20and%20the%20blue%20shape%20is%20in%20the%20mid-left.%20Translating%20the%20red%20shape%20horizontally%20to%20the%20left%2C%20it%20slides%20until%20it%20reaches%20the%20blue%20shape.%20Looking%20at%20the%20question%20output%2C%20we%20can%20verify%20that%20this%20indeed%20matches%20the%20question%20output.%0A%0A%20%20%20%20Here%20is%20another%20task.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(ds%2C%20plot_arcagi)%3A%0A%20%20%20%20plot_arcagi(ds%2C%20%22train%22%2C%2010)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20Looking%20at%20the%20examples%2C%20each%20input%20contains%20exactly%203%20diagonal%20lines%2C%20each%20a%20single%20solid%20color.%20The%20pattern%20is%20to%20repeat%20these%203%20colors%20cyclically%20across%20the%20entire%20output%20grid%20in%20diagonal%20stripes%2C%20creating%20a%20repeating%20checkered%20pattern.%20Whether%20the%20input's%203%20diagonals%20appear%20consecutively%20or%20not%20doesn't%20matter%2C%20they%20repeat%20every%203%20diagonal%20positions%20throughout%20the%20output.%0A%0A%20%20%20%20In%20Example%201%2C%20the%20input%20shows%20three%20consequtive%20diagonal%20stripes%3A%20blue%2C%20red%2C%20and%20yellow.%20The%20output%20tiles%20this%20sequence%20repeatedly%20--%20blue%20diagonal%2C%20red%20diagonal%2C%20yellow%20diagonal%20%E2%80%94-%20cycling%20through%20all%203%20colors%20across%20the%20full%20grid.%20Loking%20at%20the%20question%2C%20the%20input%20also%20contains%20three%20diagonal%20lines%20in%20blue%2C%20red%2C%20and%20yellow%2C%20but%20they're%20in%20a%20different%20order%20and%20do%20not%20appear%20all%20next%20to%20each%20other.%20Still%2C%20the%20output%20repeats%20these%20three%20colors%20cyclically%20in%20diagonal%20stripes%2C%20filling%20the%20entire%20grid.%20The%20pattern%20cycles%20every%203%20diagonals%3A%20red%2C%20blue%2C%20yellow%20over%20and%20over%20again.%20This%20produces%20the%20a%20different%20output%20than%20Example%201%20because%20the%20order%20of%20the%20three%20colors%20is%20different.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22There%20are%20hundreds%20of%20tasks%20like%20this%20in%20ARC-AGI-2.%20Solving%20each%20task%20requires%20deducing%20new%20patterns%20and%20generalizing%20to%20unforeseen%20tasks%2C%20something%20it%20is%20quite%20hard%20for%20the%20current%20crop%20of%20AI%20models.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fix_marimo_path%2C%20mo)%3A%0A%20%20%20%20arc_agi_2_leaderboard_image%20%3D%20mo.image(%0A%20%20%20%20%20%20%20%20fix_marimo_path(%22public%2Fimages%2F2025-12-05-arc-argi-2-prize-leaderboard.png%22)%2C%0A%20%20%20%20%20%20%20%20width%3D800%2C%0A%20%20%20%20%20%20%20%20caption%3D%22Performance%20on%20private%20eval%20set%20of%20ARC-AGI-2.%20Retreived%20from%20https%3A%2F%2Farcprize.org%2Fleaderboard%20on%20December%205th%2C%202025.%22%2C%0A%20%20%20%20%20%20%20%20style%3D%7B%22display%22%3A%20%22block%22%2C%20%22margin%22%3A%20%220%20auto%22%7D%0A%20%20%20%20)%0A%20%20%20%20arc_agi_2_leaderboard_image%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(f%22%22%22Even%20the%20world's%20best%20models%20struggle%20on%20ARC-AGI-2%2C%20all%20scoring%20under%20%2450%5C%25%24.%20%60Gemini%203%20Deep%20Think%20(Preview)%60%20has%20the%20highest%20score%20of%20%2445.1%5C%25%24%20but%20costs%20a%20staggering%20%24%5C%2477.16%24%20per%20task.%20%60GPT-5%20Pro%60%20is%20much%20more%20efficient%2C%20costing%20%24%5C%247.14%24%20per%20task%20but%20only%20solving%20%2418.3%5C%25%24%20of%20tasks.%20Many%20other%20frontier%20models%20--%20Claude%2C%20Grok%2C%20and%20Deepseek%20can't%20even%20crack%20%2420%5C%25%24.%20In%20contrast%2C%20humans%20%5Bget%5D(https%3A%2F%2Farcprize.org%2Fleaderboard)%20%24100%5C%25%24%20of%20questions%20right.%20That's%20why%20there%20exists%20a%20%24%5C%241%2C000%2C000%24%20%5Bcompetition%5D(https%3A%2F%2Farcprize.org%2Fcompetitions%2F2025%2F)%20to%20open%20source%20a%20solution%20to%20ARC-AGI-2.%20It's%20that%20difficult.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%20The%20HRM%20Drama%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22In%20July%2C%20HRM%20was%20released.%20It%20is%20a%20fascinating%20model%2C%20inspired%20by%20the%20human%20brain%20with%20%22slow%22%20and%20%22fast%22%20loops%20of%20computation.%20It%20gained%20a%20lot%20of%20attention%20for%20it's%20amazing%20performance%20on%20ARC-AGI-1%20despite%20its%20tiny%20size%20of%2027M%20parameters.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fix_marimo_path%2C%20mo)%3A%0A%20%20%20%20hrm_performance_image%20%3D%20mo.image(%0A%20%20%20%20%20%20%20%20fix_marimo_path(%22public%2Fimages%2Fhrm_arc_agi.png%22)%2C%0A%20%20%20%20%20%20%20%20width%3D400%2C%0A%20%20%20%20%20%20%20%20caption%3D%22HRM%20scores%20on%20public%20eval%20set%20of%20ARC-AGI-1%20and%20ARC-AGI-2.%22%2C%0A%20%20%20%20%20%20%20%20style%3D%7B%22display%22%3A%20%22block%22%2C%20%22margin%22%3A%20%220%20auto%22%7D%0A%20%20%20%20)%0A%20%20%20%20hrm_performance_image%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20HRM%20scored%2040.3%25%20on%20ARC-AGI-1%20while%20SOTA%20models%20like%20o3-mini-high%20and%20Claude-3.7-8k%20scored%2034.5%25%2C%20and%2021.2%25%20respectively%20(back%20in%20July%202025).%20It%20beat%20Anthropic's%20best%20model%20by%20nearly%20~2x!%20Similarly%2C%20it%20outperformed%20o3-mini-high%20and%20Claude-3.7-8k%20on%20ARC-AGI-2%2C%20but%20be%20warned%20that%20the%20ARC-AGI-2%20the%20scores%20are%20so%20low%20that%20they%20are%20more%20much%20suspectable%20to%20noise.%0A%0A%20%20%20%20The%20results%20almost%20seemed%20to%20be%20too%20good%20to%20be%20true.%20How%20can%20a%20tiny%2027M%20parameter%20model%20from%20a%20small%20lab%20be%20crushing%20some%20of%20the%20world's%20best%20models%2C%20at%20a%20fraction%20of%20their%20size%3F%0A%0A%20%20%20%20Turns%20out%2C%20HRM%20trained%20on%20test%3A%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fix_marimo_path%2C%20mo)%3A%0A%20%20%20%20hrm_train_on_eval_image%20%3D%20mo.image(%0A%20%20%20%20%20%20%20%20fix_marimo_path(%22public%2Fimages%2Fhrm_train_on_eval_screenshot.png%22)%2C%0A%20%20%20%20%20%20%20%20width%3D600%2C%0A%20%20%20%20%20%20%20%20caption%3D%22Screenshot%20of%20HRM%20paper%20showing%20that%20HRM%20trained%20on%20the%20public%20eval%20set%20of%20ARC-AGI-1.%22%2C%0A%20%20%20%20%20%20%20%20style%3D%7B%22display%22%3A%20%22block%22%2C%20%22margin%22%3A%20%220%20auto%22%7D%0A%20%20%20%20)%0A%0A%20%20%20%20hrm_train_on_eval_image%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20rf%22%22%22%0A%20%20%20%20In%20their%20paper%2C%20the%20HRM%20authors%20admitted%20to%20showing%20the%20model%20%22example%20pairs%20in%20the%20training%20and%20the%20**evaluation**%20sets%22.%20The%20evaluation%20set%20here%20refers%20to%20the%20public%20eval%20set%20of%20ARC-AGI-1!%20This%20sounds%20like%20training%20on%20test!%0A%0A%20%20%20%20On%20github%2C%20the%20HRM%20authors%20clarified%20that%20they%20only%20trained%20on%20the%20*examples*%20of%20the%20public%20eval%20set%2C%20not%20the%20*questions*%20of%20the%20public%20eval%20set.%20This%20%22contraversy%22%20set%20AI%20twitter%20on%20fire%20%5B%5B1%5D(https%3A%2F%2Fx.com%2FDorialexander%2Fstatus%2F1951954826545238181)%2C%20%5B2%5D(https%3A%2F%2Fgithub.com%2Fsapientinc%2FHRM%2Fissues%2F18)%2C%20%5B3%5D(https%3A%2F%2Fgithub.com%2Fsapientinc%2FHRM%2Fissues%2F1)%20%5B4%5D(https%3A%2F%2Fgithub.com%2Fsapientinc%2FHRM%2Fpull%2F22)%20%5B5%5D(https%3A%2F%2Fx.com%2Fb_arbaretier%2Fstatus%2F1951701328754852020)%5D%20!%20Does%20this%20actually%20count%20as%20%22training%20on%20test%22%3F%20The%20HRM%20authors%20never%20actually%20trained%20on%20the%20the%20questions%20used%20to%20measure%20model%20performance%2C%20just%20the%20examples%20associated%20with%20them.%20However%2C%20these%20have%20very%20similar%20distributions...%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20Ultimately%20the%20ARC-AGI%20organizers%20accepted%20HRM's%20submision%20and%20the%20concsensus%20on%20%5BTwitter%5D(https%3A%2F%2Fx.com%2FDorialexander%2Fstatus%2F1951954826545238181)%20was%20that%20it's%20actually%20completely%20allowed%20to%20train%20on%20the%20*examples*%20of%20the%20public%20eval%20set.%20But%20buried%20in%20a%20GitHub%20thread%2C%20HRM's%20lead%20author%2C%20Guan%20Wang%2C%20made%20an%20offhand%20comment%20that%20caught%20my%20attention%3A%0A%20%20%20%20%3E%20%22If%20there%20were%20genuine%20100%25%20data%20leakage%20-%20then%20model%20should%20have%20very%20close%20to%20100%25%20performance%20(perfect%20memorization).%22%20-%20%20%20%5BGuan%20Wang%5D(https%3A%2F%2Fgithub.com%2Fsapientinc%2FHRM%2Fissues%2F1%23issuecomment-3113214308)%0A%0A%20%20%20%20That%20line%20stuck%20with%20me.%20If%20partial%20leakage%20gets%20you%20%2440.3%5C%25%24%20on%20ARC-AGI-1%2C%20what%20happens%20with%20*complete*%20leakage%3F%20If%20we%20train%20on%20the%20actual%20test%20questions%2C%20not%20just%20test%20examples%2C%20can%20we%20hit%20%24100%5C%25%24%3F%20Can%20we%20do%20it%20with%20even%20fewer%20parameters%20than%20HRM%20(27M)%20or%20TRM%20(7M)%3F%20And%20can%20we%20do%20it%20on%20the%20more%20challenging%20ARC-AGI-2%20instead%20of%20ARC-AGI-1%3F%20How%20far%20can%20we%20push%20this%3F%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20Chaos%20Theory%0A%0A%20%20%20%20%3E%20%22Chaos%20is%20what%20killed%20the%20dinosaurs%2C%20darling.%22%20-%20J.D.%20in%20Heathers%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20My%20goal%20was%20simple%3A%20create%20the%20tiniest%20possible%20model%20that%20achieves%20perfect%20performance%20on%20ARC-AGI-2%20by%20blatantly%20training%20on%20the%20public%20eval%20set%2C%20both%20the%20examples%20and%20questions.%20We%20would%20deviate%20from%20HRM's%20acceptable%20approach%20(training%20on%20just%20the%20examples%20of%20the%20public%20eval%20set)%20and%20enter%20the%20morally%20dubious%20territory%20of%20training%20on%20the%20examples%20*and%20questions*%20of%20the%20public%20eval%20set.%0A%0A%20%20%20%20Now%2C%20the%20obvious%20approach%20would%20be%20to%20build%20a%20dictionary%20-%20just%20map%20each%20input%20directly%20to%20its%20corresponding%20output.%20But%20that's%20boring%20and%20lookup%20tables%20aren't%20nice%20mathematical%20functions.%20They're%20discrete%2C%20discontinuous%2C%20and%20definitely%20not%20differentiable.%20We%20need%20something%20else%2C%20something%20more%20elegant%20and%20interesting.%20To%20do%20that%2C%20we%20are%20going%20to%20take%20a%20brief%20detour%20into%20the%20world%20of%20chaos%20theory.%0A%0A%20%20%20%20%3E%20Note%3A%20As%20far%20as%20I%20know%2C%20Steven%20Piantadosi%20pioneered%20this%20technique%20in%20%5BOne%20parameter%20is%20always%20enough%5D(https%3A%2F%2Fcolala.berkeley.edu%2Fpapers%2Fpiantadosi2018one.pdf).%20Yet%20I%20first%20heard%20of%20it%20through%20Laurent%20Bou%C3%A9's%20paper%20%5BReal%20numbers%2C%20data%20science%20and%20chaos%3A%20How%20to%20fit%20any%20dataset%20with%20a%20single%20parameter%5D(https%3A%2F%2Farxiv.org%2Fabs%2F1904.12320).%20This%20paper%20is%20really%20a%20gem%20due%20its%20sheer%20creativity.%0A%0A%20%20%20%20In%20chaos%20theory%2C%20the%20dyadic%20map%20%24%5Cmathcal%7BD%7D%24%20is%20a%20simple%20one-dimensional%20chaotic%20system%20defined%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign%7D%0A%20%20%20%20%5Cmathcal%7BD%7D(a)%0A%20%20%20%20%26%3D%0A%20%20%20%20(2a)%20%5Cbmod%201%0A%20%20%20%20%26%0A%20%20%20%20%5Cmathcal%7BD%7D%3A%20%5B0%2C%201%5D%20%5Cto%20%5B0%2C%201%5D.%0A%20%20%20%20%5Ctag%7B2%7D%0A%20%20%20%20%5Cend%7Balign%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20It%20takes%20in%20any%20number%20between%200%20and%201%2C%20doubles%20it%2C%20and%20throws%20away%20the%20whole%20number%20part%2C%20leaving%20just%20the%20fraction.%20That's%20it.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.function%0Adef%20D(a)%3A%20return%20(2%20*%20a)%20%25%201%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20plt)%3A%0A%20%20%20%20def%20_()%3A%0A%20%20%20%20%20%20%20%20a_values%20%3D%20np.linspace(0%2C%201%2C%20100)%0A%20%20%20%20%20%20%20%20fig%2C%20ax%20%3D%20plt.subplots()%0A%20%20%20%20%20%20%20%20ax.scatter(a_values%2C%20D(a_values)%2C%20label%3D%22Dyadic%22%2C%20s%3D2)%0A%20%20%20%20%20%20%20%20ax.set_xlabel(r%22%24a%24%22)%0A%20%20%20%20%20%20%20%20ax.set_ylabel(r%22%24%5Cmathcal%7BD%7D(a)%24%22)%0A%20%20%20%20%20%20%20%20ax.set_title(%22Dyadic%20Map%22)%0A%20%20%20%20%20%20%20%20ax.legend()%0A%20%20%20%20%20%20%20%20%23%20plt.show()%0A%20%20%20%20%20%20%20%20return%20fig%0A%0A%20%20%20%20_()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20In%20chaos%20theory%2C%20we%20often%20study%20the%20orbit%20or%20trajectory%20of%20a%20chaotic%20system%2C%20the%20sequence%20generated%20by%20applying%20the%20chaotic%20map%20to%20itself%20over%20and%20over%20again.%20Starting%20with%20some%20number%20%24a%24%2C%20we%20apply%20our%20map%20to%20get%20%24%5Cmathcal%7BD%7D(a)%24%2C%20and%20again%20to%20get%20%24%5Cmathcal%7BD%7D(%5Cmathcal%7BD%7D(a))%24%2C%20and%20so%20on%20and%20so%20forth.%20Let%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Cmathcal%7BD%7D%5Ek(a)%0A%20%20%20%20%26%20%3A%3D%0A%20%20%20%20%5Cunderbrace%7B(D%20%5Ccirc%20...%20%5Ccirc%20D)%7D_%7Bk%7D(a)%20%3D%20(2%5Ek%20a)%20%5Cmod%201%0A%20%20%20%20%5Ctag%7B3%7D%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20mean%20we%20apply%20the%20dyadic%20map%20%24k%24%20times%20to%20%24a%24.%20What%20does%20the%20orbit%20%24(a%2C%20%5Cmathcal%7BD%7D%5E1(a)%2C%20%5Cmathcal%7BD%7D%5E2(a)%2C%20%5Cmathcal%7BD%7D%5E3(a)%2C%20%5Cmathcal%7BD%7D%5E4(a)%2C%20%5Cmathcal%7BD%7D%5E5(a))%24%20look%20like%3F%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.function%0Adef%20dyadic_orbit(a_L%2C%20k)%3A%0A%20%20%20%20orbits%20%3D%20%5Ba_L%5D%0A%20%20%20%20for%20_%20in%20range(k)%3A%0A%20%20%20%20%20%20%20%20orbits.append(D(orbits%5B-1%5D))%0A%20%20%20%20return%20orbits%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20dyadic_orbit1%20%3D%20dyadic_orbit(0.5%2C%205)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20dyadic_orbit2%20%3D%20dyadic_orbit(1%2F3%2C%205)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20dyadic_orbit3%20%3D%20dyadic_orbit(0.431%2C%205)%0A%20%20%20%20return%20(dyadic_orbit3%2C)%0A%0A%0A%40app.cell%0Adef%20_(decimal_to_binary%2C%20dyadic_orbit3)%3A%0A%20%20%20%20dyadic_orbit3_binary%20%3D%20%5Bdecimal_to_binary(x%2C%20len(dyadic_orbit3)-i)%5B0%5D%20for%20i%2C%20x%20in%20enumerate(dyadic_orbit3)%5D%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20*%20If%20%24a%20%3D%200.5%24%2C%20the%20orbit%20is%20%24(0.5%2C%200.0%2C%200.0%2C%200.0%2C%200.0%2C%200.0)%24.%0A%20%20%20%20*%20If%20%24a%20%3D%201%2F3%24%2C%20the%20orbit%20is%20%24(0.333%2C%200.667%2C%200.333%2C%200.667%2C%200.333%2C%200.667%2C)%24%0A%20%20%20%20*%20If%20%24a%20%3D%200.431%24%2C%20the%20orbit%20is%20%24(0.431%2C%200.862%2C%200.724%2C%200.448%2C%200.897%2C%200.792)%24%0A%0A%20%20%20%20One%20orbit%20seems%20to%20end%20in%20all%20zeros%2C%20another%20bounces%20back%20and%20forth%20between%20%240.333%24%20and%20%240.667%24%2C%20and%20a%20third%20seems%20to%20have%20no%20pattern%20at%20all.%20On%20the%20surface%2C%20these%20orbits%20do%20not%20have%20much%20in%20common.%20But%20if%20we%20take%20a%20closer%20look%2C%20they%20all%20share%20the%20same%20underlying%20pattern.%0A%0A%20%20%20%20Let's%20revisit%20the%20third%20orbit%20for%20%24a%20%3D%200.431%24%20but%20this%20time%20we%20will%20analyze%20its%20binary%20representation%3A%0A%0A%20%20%20%20%7C%20Iterations%20%7C%20Decimal%20%7C%20Binary%20%7C%20Observation%20%7C%0A%20%20%20%20%7C------------%7C------------------------%7C----------------------%7C-------------%7C%0A%20%20%20%20%7C%200%20%7C%20%24a%20%3D%200.431%24%20%7C%20%24%5Ctext%7Bbin%7D(a)%20%3D%200.011011...%24%20%7C%20Original%20number%20%7C%0A%20%20%20%20%7C%201%20%7C%20%24D%5E1(a)%20%3D%200.862%24%20%7C%20%24%5Ctext%7Bbin%7D(D%5E1(a))%20%3D%200.11011...%24%20%7C%20First%20bit%20of%20%24a%24%20%24(0)%24%20removed%20%7C%0A%20%20%20%20%7C%202%20%7C%20%24D%5E2(a)%20%3D%200.724%24%20%7C%20%24%5Ctext%7Bbin%7D(D%5E2(a))%20%3D%200.1011...%24%20%7C%20First%20two%20bits%20of%20%24a%24%20%24(01)%24%20removed%20%7C%0A%20%20%20%20%7C%203%20%7C%20%24D%5E3(a)%20%3D%200.448%24%20%7C%20%24%5Ctext%7Bbin%7D(D%5E3(a))%20%3D%200.011...%24%20%7C%20First%20three%20bits%20of%20%24a%24%20%24(011)%24%20removed%20%7C%0A%20%20%20%20%7C%204%20%7C%20%24D%5E4(a)%20%3D%200.897%24%20%7C%20%24%5Ctext%7Bbin%7D(D%5E4(a))%20%3D%200.11...%24%20%7C%20First%20four%20bits%20of%20%24a%24%20%24(0110)%24%20removed%20%7C%0A%20%20%20%20%7C%205%20%7C%20%24D%5E5(a)%20%3D%200.792%24%20%7C%20%24%5Ctext%7Bbin%7D(D%5E5(a))%20%3D%200.1...%24%20%7C%20First%20four%20bits%20of%20%24a%24%20%24(01101)%24%20removed%20%7C%0A%0A%20%20%20%20Looking%20at%20the%20Binary%20column%2C%20we%20see%20that%20**every%20time%20we%20apply%20the%20dyadic%20map%2C%20the%20most%20significant%20bit%20is%20removed**!%20We%20start%20off%20with%20%240.011011%24%2C%20and%20then%20applying%20%24%5Cmathcal%7BD%7D%24%20once%20removes%20the%20leftmost%20%240%24%20to%20get%20%240.11011%24%2C%20and%20applying%20%24%5Cmathcal%7BD%7D%24%20another%20time%20removes%20the%20leftmost%20%241%24%20to%20get%20%240.1011%24.%20Although%20the%20orbit%20appears%20irregular%20in%20its%20decimal%20representation%2C%20a%20clear%20pattern%20emerges%20from%20the%20binary%20representation.%0A%0A%20%20%20%20What%20is%20going%20on%20here%3F%0A%0A%20%20%20%20Each%20time%20we%20call%20%24D(a)%20%3D%20(2a)%20%5Cmod%201%24%2C%20we%20double%20and%20truncate%20%24a%24.%20The%20doubling%20shifts%20every%20binary%20digit%20one%20place%20to%20the%20left%20and%20the%20truncation%20throws%20away%20whatever%20digit%20lands%20in%20the%20one's%20place.%20In%20other%20words%2C%20each%20application%20of%20%24%5Cmathcal%7BD%7D%24%20peels%20off%20the%20first%20binary%20digit%20and%20throws%20it%20away.%20**If%20we%20apply%20the%20dyadic%20map%20%24k%24%20times%2C%20we%20remove%20the%20first%20%24k%24%20bits%20of%20%24a%24.**%0A%0A%20%20%20%20We%20can%20see%20this%20process%20also%20holds%20for%20our%20other%20orbits%3A%0A%0A%20%20%20%20*%20If%20%24a%20%3D%200.5%24%2C%20we%20get%20the%20orbit%20%24(0.5%2C%200.0%2C%200.0%2C%200.0%2C%200.0%2C%200.0)%24%20because%20%24%5Ctext%7Bbin%7D(a)%20%3D%200.100000...%24%20and%20after%20discarding%20the%20first%20bit%2C%20which%20is%20a%20%241%24%2C%20we%20are%20left%20with%20all%20zeros.%0A%20%20%20%20*%20If%20%24a%20%3D%201%2F3%24%2C%20we%20get%20the%20orbit%20%24(0.333%2C%200.667%2C%200.333%2C%200.667%2C%200.333%2C%200.667)%24%20because%20%24%5Ctext%7Bbin%7D(a)%20%3D%200.010101...%24%2C%20an%20infinite%20sequence%20of%20bits%20alternating%20between%20%241%24%20and%20%240%24.%20When%20the%20bits%20start%20with%20a%200%2C%20we%20get%20%240.010101...%24%20which%20is%20%241%2F3%20%3D%200.333%24%20in%20decimal.%20And%20when%20the%20bits%20start%20with%20a%20%241%24%2C%20%240.10101...%24%2C%20we%20get%20%242%2F3%20%3D%200.667%24%20in%20decimal.%0A%0A%20%20%20%20Remarkably%2C%20these%20orbits%20are%20all%20governed%20by%20the%20same%20rule%3A%20remove%20one%20bit%20of%20information%20every%20time%20the%20dyadic%20map%20is%20applied.%20As%20each%20application%20of%20%24%5Cmathcal%7BD%7D%24%20removes%20another%20bit%2C%20this%20moves%20us%20deeper%20into%20the%20less%20significant%20digits%20of%20our%20original%20number%20--%20the%20digits%20that%20are%20most%20sensitive%20to%20noise%20and%20measurement%20errors.%20A%20tiny%20change%20in%20%24a%24%20due%20to%20noise%2C%20affecting%20the%20least%20significant%20bits%20of%20%24a%24%2C%20would%20eventually%20bubble%20up%20to%20the%20surface%20and%20completely%20change%20the%20orbit.%20That's%20why%20this%20system%20is%20so%20chaotic%20--%20it%20is%20incredibly%20sensitive%20to%20even%20the%20smallest%20changes%20in%20the%20initial%20value%20%24a%24.%0A%0A%20%20%20%20(Note%3A%20we%20always%20compute%20the%20dyadic%20map%20on%20*decimal*%20numbers%2C%20not%20binary%20numbers%3B%20however%2C%20conceptually%20it%20is%20helpful%20to%20think%20about%20the%20binary%20representations%20of%20the%20orbit.)%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20The%20Dyadic%20Map%20As%20An%20ML%20Model%0A%20%20%20%20%3E%20%22When%20I%20grow%20up%2C%20I'm%20going%20to%20be%20a%20real%20~~boy~~%20ML%20Model%22%20-%20the%20Dyadic%20Map%20if%20it%20were%20staring%20in%20Pinacoi%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20p_%20%3D%206%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20%23%20initalize%20alpha%0A%20%20%20%20%23%20b1%20%3D%20decimal_to_binary(0.5%2C%20p_)%5B0%5D%0A%20%20%20%20%23%20b2%20%3D%20decimal_to_binary(1%2F3%2C%20p_)%5B0%5D%0A%20%20%20%20%23%20b3%20%3D%20decimal_to_binary(0.43085467085%2C%20p_)%5B0%5D%0A%20%20%20%20%23%20b%20%3D%20''.join(%5Bb1%2C%20b2%2C%20b3%5D)%0A%20%20%20%20%23%20print(f'%7Bb1%3D%7D%5Cn%7Bb2%3D%7D%5Cn%7Bb3%3D%7D%5Cn%7Bb%3D%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20alpha0_dec%20%3D%20binary_to_decimal(b)%0A%20%20%20%20%23%20alpha0_bin%20%3D%20decimal_to_binary(alpha0_dec%2C%2018)%5B0%5D%0A%20%20%20%20%23%20b0_pred_bin%20%3D%20decimal_to_binary(alpha0_dec%2C%20p_)%5B0%5D%0A%20%20%20%20%23%20x0_pred_dec%20%3D%20binary_to_decimal(b0_pred_bin)%0A%20%20%20%20%23%20print(f'%7Balpha0_dec%3D%7D%5Cn%7Balpha0_bin%3D%7D%5Cnbin(alpha)%5B0%3A6%5D%3D%7Bb0_pred_bin%7D%5Cnx%5E_0%3Ddec(bin(alpha)%5B0%3A6%5D)%3D%7Bx0_pred_dec%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20alpha1_dec%20%3D%20dyadic_orbit(alpha0_dec%2C%20p_)%5B-1%5D%0A%20%20%20%20%23%20alpha1_bin%20%3D%20decimal_to_binary(alpha1_dec%2C%2018-p_)%5B0%5D%0A%20%20%20%20%23%20b1_pred_bin%20%3D%20decimal_to_binary(alpha1_dec%2C%20p_)%5B0%5D%0A%20%20%20%20%23%20x1_pred_dec%20%3D%20binary_to_decimal(b1_pred_bin)%0A%20%20%20%20%23%20print(f'%7Balpha1_dec%3D%7D%5Cn%7Balpha1_bin%3D%7D%5Cnbin(D%5E6(alpha))%5B0%3A6%5D%3D%7Bb1_pred_bin%7D%5Cnx%5E_1%3Ddec(bin(D%5E6(alpha))%5B0%3A6%5D)%3D%7Bx1_pred_dec%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20alpha2_dec%20%3D%20dyadic_orbit(alpha1_dec%2C%20p_)%5B-1%5D%0A%20%20%20%20%23%20alpha2_bin%20%3D%20decimal_to_binary(alpha2_dec%2C%2018-2*p_)%5B0%5D%0A%20%20%20%20%23%20b2_pred_bin%20%3D%20decimal_to_binary(alpha2_dec%2C%20p_)%5B0%5D%0A%20%20%20%20%23%20x2_pred_dec%20%3D%20binary_to_decimal(b2_pred_bin)%0A%20%20%20%20%23%20print(f'%7Balpha2_dec%3D%7D%5Cn%7Balpha2_bin%3D%7D%5Cnbin(D%5E12(alpha))%5B0%3A6%5D%3D%7Bb2_pred_bin%7D%5Cnx%5E_2%3Ddec(bin(D%5E12(alpha))%5B0%3A6%5D)%3D%7Bx2_pred_dec%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22We've%20discovered%20something%20remarkable%3A%20each%20application%20of%20%24%5Cmathcal%7BD%7D%24%20peels%20away%20exactly%20one%20bit.%20But%20here's%20the%20question%3A%20if%20the%20dyadic%20map%20can%20systematically%20extract%20a%20number's%20bits%2C%20is%20it%20possible%20to%20put%20information%20in%20those%20bits%20in%20the%20first%20place%3F%20**What%20if%20we%20encode%20our%20dataset%20into%20a%20number's%20bits%20(%60model.fit%60)%20and%20then%20use%20the%20dyadic%20map%20as%20the%20core%20of%20a%20predictive%20model%2C%20extracting%20out%20the%20answer%20bit%20by%20bit%20(%60model.predict%60)%3F**%20In%20other%20words%2C%20can%20we%20turn%20the%20dyadic%20map%20into%20an%20ML%20model%3F%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20A%20Worked%20Example%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20Suppose%20our%20dataset%20contains%20the%20three%20numbers%20we%20saw%20before%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathcal%7BX%7D%0A%20%20%20%20%3D%0A%20%20%20%20%5C%7Bx_0%2C%20x_1%2C%20x_2%5C%7D%0A%20%20%20%20%3D%0A%20%20%20%20%5C%7B0.5%2C%201%2F3%2C%20%200.431%5C%7D.%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Let's%20convert%20each%20number%20to%20binary%20and%20look%20at%20the%20first%20%24p%3D6%24%20binary%20digits%20for%20simplicity%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathcal%7BB%7D%0A%20%20%20%20%3D%0A%20%20%20%20%5C%7Bb_0%2C%20b_1%2C%20b_2%5C%7D%0A%20%20%20%20%3D%0A%20%20%20%20%5C%7B%20%5Ctext%7Bbin%7D_6(x_0)%2C%20%5Ctext%7Bbin%7D_6(x_1)%2C%20%5Ctext%7Bbin%7D_6(x_2)%5C%7D%0A%20%20%20%20%3D%0A%20%20%20%20%5C%7B0.100000%2C%200.010101%2C%200.011011%5C%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20the%20function%20%24b_i%20%3D%20%5Ctext%7Bbin%7D_p(x_i)%24%20converts%20decimal%20numbers%20to%20%24p%24-bit%20binary%20numbers.%20Now%20comes%20the%20clever%20part%3A%20we%20glue%20these%20binary%20strings%20together%2C%20end%20to%20end%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20b%0A%20%20%20%20%3D%0A%20%20%20%200.%0A%20%20%20%20%5Cunderbrace%7B100000%7D_%7Bb_0%7D%0A%20%20%20%20%5Cunderbrace%7B010101%7D_%7Bb_1%7D%0A%20%20%20%20%5Cunderbrace%7B011011%7D_%7Bb_2%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20and%20convert%20this%20binary%20string%20back%20to%20decimal%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Calpha%20%3D%20%5Ctext%7Bdec%7D(b)%20%3D%200.50522994995117188%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20number%20%24%5Calpha%24%20is%20carefully%20engineered%20so%20that%20it%20is%20a%20decimal%20number%20whose%20bits%20contain%20our%20entire%20dataset's%20binary%20representation.%20That's%20right%3A%20**we've%20just%20compressed%20our%20entire%20dataset%20into%20a%20single%20decimal%20number!**%20We%20only%20have%20one%20parameter%2C%20not%20billions%20here!%20This%20is%20a%20very%20simple%2C%20stupid%20version%20of%20%24%5Calpha%20%3D%20%5Ctext%7Bmodel.fit%7D(%5Cmathcal%7BX%7D)%24.%0A%0A%20%20%20%20But%20here's%20the%20question%3A%20given%20%24%5Calpha%24%2C%20how%20do%20we%20get%20our%20data%20%24%5Cmathcal%7BX%7D%24%20back%20out%3F%20How%20do%20we%20do%20%24%5Ctilde%7Bx%7D_i%20%3D%20%5Ctext%7Bmodel.predict%7D(%5Calpha)%24%3F%20This%20is%20where%20the%20dyadic%20map%20becomes%20our%20extraction%20tool.%0A%0A%20%20%20%20*Step%201.*%20Trivially%2C%20we%20know%20the%20first%206%20bits%20of%20%24%5Calpha%24%20contains%20%24b_0%24.%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%20%20%20%20%5Calpha%0A%20%20%20%20%20%20%20%20%26%3D%0A%20%20%20%20%20%20%20%200.50522994995117188%0A%20%20%20%20%20%20%20%20%5C%5C%0A%20%20%20%20%20%20%20%20%5Ctext%7Bbin%7D(%5Calpha)%0A%20%20%20%20%20%20%20%20%26%3D%0A%20%20%20%20%20%20%20%200.%5Cunderbrace%7B100000%7D_%7Bb_0%7D%5Cunderbrace%7B010101%7D_%7Bb_1%7D%5Cunderbrace%7B011011%7D_%7Bb_2%7D%0A%20%20%20%20%20%20%20%20%3D%0A%20%20%20%20%20%20%20%200.100000010101011011%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20So%20we'll%20just%20record%20the%20first%20%246%24%20bits%20of%20%24%5Calpha%24%20to%20get%20%24b_0%24.%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%20%20%20%20b_0%0A%20%20%20%20%20%20%20%20%26%3D%0A%20%20%20%20%20%20%20%20%5Ctext%7Bbin%7D(%5Calpha)_%7B0%3A6%7D%0A%20%20%20%20%20%20%20%20%3D%0A%20%20%20%20%20%20%20%20100000%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20If%20we%20convert%20this%20number%20%24b_0%24%20back%20to%20decimal%2C%20we'll%20recover%20our%20original%20data%2C%20up%20to%20the%20first%20%246%24%20digits%20of%20precision.%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%20%20%20%20%5Ctilde%7Bx%7D_0%0A%20%20%20%20%20%20%20%20%26%3D%0A%20%20%20%20%20%20%20%20%5Ctext%7Bdec%7D%20(%20b_0%20)%0A%20%20%20%20%20%20%20%20%3D%0A%20%20%20%20%20%20%20%200.500000%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Now%20from%20%24%5Calpha%24%20we've%20extracted%20the%20prediction%20%24%5Ctilde%7Bx%7D_0%20%3D%200.500000%24%20which%20matches%20exactly%20the%20%240%24th%20sample%20of%20our%20dataset%20%24x_0%20%3D%200.5%24.%0A%0A%20%20%20%20*Step%202.*%20To%20predict%20the%20next%20number%2C%20%24%5Ctilde%7Bx%7D_1%24%2C%20remember%20that%20each%20application%20of%20%24%5Cmathcal%7BD%7D%24%20strips%20away%20the%20leftmost%20binary%20digit.%20So%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%20%20%20%20D%5E6(%5Calpha)%0A%20%20%20%20%20%20%20%20%26%3D%0A%20%20%20%20%20%20%20%200.334716796875%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20strips%20away%20the%20first%20%246%24%20bits%20of%20%24%5Calpha%24%2C%20which%20just%20removes%20%24b_0%24%2C%20and%20leaves%20us%20with%20%24b_1%2C%20b_2%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%20%20%20%20%5Ctext%7Bbin%7D(D%5E6(%5Calpha))%0A%20%20%20%20%20%20%20%20%26%3D%0A%20%20%20%20%20%20%20%200.%5Cunderbrace%7B%5Chspace%7B1cm%7D%7D_%7Bb_0%7D%5Cunderbrace%7B010101%7D_%7Bb_1%7D%5Cunderbrace%7B011011%7D_%7Bb_2%7D%0A%20%20%20%20%20%20%20%20%3D%0A%20%20%20%20%20%20%20%200.010101011011%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Like%20before%2C%20we'll%20then%20record%20the%20first%20%246%24%20bits%20of%20%24D%5E6(%5Calpha)%24%20to%20get%20%24b_1%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%20%20%20%20b_1%0A%20%20%20%20%20%20%20%20%26%3D%0A%20%20%20%20%20%20%20%20%5Ctext%7Bbin%7D(D%5E6(%5Calpha))_%7B0%3A6%7D%0A%20%20%20%20%20%20%20%20%3D%0A%20%20%20%20%20%20%20%20010101%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20and%20convert%20%24b_1%24%20back%20to%20decimal%20to%20get%20%24%5Ctilde%7Bx%7D_1%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%20%20%20%20%5Ctilde%7Bx%7D_1%0A%20%20%20%20%20%20%20%20%26%3D%0A%20%20%20%20%20%20%20%20%5Ctext%7Bdec%7D%20(b_1)%0A%20%20%20%20%20%20%20%20%3D%0A%20%20%20%20%20%20%20%200.328125%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Here%20our%20prediction%20%24%5Ctilde%7Bx%7D_1%20%3D%200.328125%24%20is%20slightly%20off%20from%20the%20true%20value%20%24x_1%20%3D%201%2F3%24%20due%20to%20the%20limits%20of%20%246%24-bit%20precision.%20If%20we'd%20have%20more%20digits%20of%20precision%20and%20increase%20%24p%24%2C%20%24%5Ctilde%7Bx%7D_1%24%20would%20be%20closer%20to%20%24x_1%24.%0A%0A%20%20%20%20*Step%203.*%20To%20get%20the%20next%20number%2C%20%24b_2%24%2C%20apply%20%24%5Cmathcal%7BD%7D%24%20another%206%20times%20to%20remove%20a%20total%20of%20%2412%24%20bits%20from%20%24%5Calpha%24%2C%20%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%20%20%20%20D%5E%7B12%7D(%5Calpha)%0A%20%20%20%20%20%20%20%20%26%3D%0A%20%20%20%20%20%20%20%200.421875%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20which%20strips%20off%20%24b_0%2C%20b_1%24%20and%20leaves%20us%20with%20just%20%24b_2%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%20%20%20%20%5Ctext%7Bbin%7D(D%5E%7B12%7D(%5Calpha))%0A%20%20%20%20%20%20%20%20%26%3D%0A%20%20%20%20%20%20%20%200.%5Cunderbrace%7B%5Chspace%7B1cm%7D%7D_%7Bb_0%7D%5Cunderbrace%7B%5Chspace%7B1cm%7D%7D_%7Bb_1%7D%5Cunderbrace%7B011011%7D_%7Bb_2%7D%0A%20%20%20%20%20%20%20%20%3D%0A%20%20%20%20%20%20%20%200.011011%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Like%20before%2C%20we'll%20then%20record%20the%20first%20%246%24%20bits%20of%20%24D%5E%7B12%7D(%5Calpha)%24%20to%20get%20%24b_2%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%20%20%20%20b_2%0A%20%20%20%20%20%20%20%20%26%3D%0A%20%20%20%20%20%20%20%20%5Ctext%7Bbin%7D(D%5E%7B12%7D(%5Calpha))_%7B0%3A6%7D%0A%20%20%20%20%20%20%20%20%3D%0A%20%20%20%20%20%20%20%20011011%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20and%20convert%20%24b_2%24%20back%20to%20decimal%20to%20get%20%24%5Ctilde%7Bx%7D_2%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%20%20%20%20%5Ctilde%7Bx%7D_2%0A%20%20%20%20%20%20%20%20%26%3D%0A%20%20%20%20%20%20%20%20%5Ctext%7Bdec%7D%20(b_2)%0A%20%20%20%20%20%20%20%20%3D%0A%20%20%20%20%20%20%20%200.421875%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Notice%20again%20that%20our%20prediction%20%24%5Ctilde%7Bx%7D_2%20%3D%200.421875%24%20is%20slightly%20off%20from%20the%20true%20value%20%24x_2%20%3D%200.431%24%20due%20to%20the%20limitations%20of%20%246%24-bit%20precision.%20%0A%0A%20%20%20%20Let%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%20%20%20%20%5Ctilde%7B%5Cmathcal%7BX%7D%7D%0A%20%20%20%20%20%20%20%20%26%3D%0A%20%20%20%20%20%20%20%20%5Cbig%20%5C%7B%5Ctilde%7Bx%7D_0%2C%20%5Ctilde%7Bx%7D_1%2C%20%5Ctilde%7Bx%7D_2%20%5Cbig%5C%7D%0A%20%20%20%20%20%20%20%20%3D%0A%20%20%20%20%20%20%20%20%5Cbig%20%5C%7B%200.500000%2C%20%200.328125%2C%200.421875%20%5Cbig%20%5C%7D%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20be%20the%20predictions%20made%20by%20our%20strange%20dyadic%20model.%20If%20everything%20is%20correct%2C%20our%20predicted%20dataset%20%24%5Ctilde%7B%5Cmathcal%7BX%7D%7D%24%20should%20perfectly%20equal%20our%20original%20dataset%20%24%5Cmathcal%7BX%7D%24%20up%20to%20the%20first%20%24p%24%20bits.%0A%0A%0A%20%20%20%20These%203%20steps%20are%20summerized%20in%20the%20table%20below.%0A%0A%20%20%20%20%7C%20Iteration%20%24i%24%20%7C%24ip%24%20bits%20removed%20%7C%20%24%5Cmathcal%7BD%7D%5E%7Bip%7D(%5Calpha)%24%20in%20decimal%20%7C%20%24%5Cmathcal%7BD%7D%5E%7Bip%7D(%5Calpha)%24%20in%20binary%20%7C%20%24b_i%24%2C%20the%20first%20%24p%24%20bits%20of%20%24%5Cmathcal%7BD%7D%5E%7Bip%7D(%5Calpha)%24%20in%20binary%20%7C%20%20%24%5Ctilde%7Bx%7D_i%24%2C%20the%20first%20%24p%24%20bits%20of%20%24%5Cmathcal%7BD%7D%5E%7Bip%7D(%5Calpha)%24%20in%20decimal%7C%0A%20%20%20%20%7C------------%7C------------------------%7C----------------------%7C-------------%7C-------------%7C-------------%7C%0A%20%20%20%20%7C%20%240%24%20%7C%20%240%20%5Ccdot%206%20%3D%200%24%20%7C%20%24%5Calpha%20%3D%200.50522994995117188%24%20%7C%20%24%5Ctext%7Bbin%7D(%5Calpha)%20%3D%200.%5Cunderbrace%7B100000%7D_%7Bb_0%7D%5Cunderbrace%7B010101%7D_%7Bb_1%7D%5Cunderbrace%7B011011%7D_%7Bb_2%7D%24%20%7C%20%24b_0%20%3D%20010101%24%20%7C%20%24%5Ctilde%7Bx%7D_0%20%3D%200.500000%24%7C%0A%20%20%20%20%7C%20%241%24%20%7C%20%241%20%5Ccdot%206%20%3D%206%24%20%7C%20%24%5Cmathcal%7BD%7D%5E6(%5Calpha)%20%3D%200.33471679687500000%24%20%7C%20%24%5Ctext%7Bbin%7D(D%5E6(%5Calpha))%20%3D%200.%5Cunderbrace%7B%5Chspace%7B1cm%7D%7D_%7Bb_0%7D%5Cunderbrace%7B010101%7D_%7Bb_1%7D%5Cunderbrace%7B011011%7D_%7Bb_2%7D%24%20%7C%20%24b_1%20%3D%20010101%24%7C%20%24%5Ctilde%7Bx%7D_1%20%3D%200.328125%24%7C%0A%20%20%20%20%7C%20%242%24%20%7C%20%242%20%5Ccdot%206%20%3D%2012%24%20%7C%20%24%5Cmathcal%7BD%7D%5E%7B12%7D(%5Calpha)%20%3D%200.42187500000000000%24%20%7C%20%24%5Ctext%7Bbin%7D(D%5E%7B12%7D(%5Calpha))%20%3D%200.%5Cunderbrace%7B%5Chspace%7B1cm%7D%7D_%7Bb0%7D%5Cunderbrace%7B%5Chspace%7B1cm%7D%7D_%7Bb1%7D%5Cunderbrace%7B011011%7D_%7Bb_2%7D%24%20%7C%20%24b_2%20%3D%20011011%24%7C%20%24%5Ctilde%7Bx%7D_2%20%3D%200.421875%24%7C%0A%0A%20%20%20%20In%20decimal%2C%20we%20go%20from%20%24%5Calpha%20%3D%200.50522994995117188%24%20to%20%24%5Cmathcal%7BD%7D%5E6(%5Calpha)%20%3D%200.33471679687500000%24%20and%20then%20to%20%24%5Cmathcal%7BD%7D%5E%7B12%7D(%5Calpha)%20%3D%200.42187500000000000%24.%20Although%20this%20pattern%20looks%20completely%20random%2C%20we%20are%20shifitng%20bits%20with%20superb%20precision.%20This%20is%20anything%20but%20random.%0A%0A%20%20%20%20Think%20about%20what%20we've%20accomplished%20here.%20We%20just%20showed%20that%20you%20can%20take%20a%20dataset%20compress%20it%20down%20to%20a%20single%20real%20number%2C%20%24%5Calpha%24.%20Then%2C%20using%20nothing%20more%20than%20repeated%20doubling%20and%20truncation%20via%20%24%5Cmathcal%7BD%7D%24%2C%20we%20can%20perfectly%20recover%20every%20data%20point%20%24%5Ctilde%7B%5Cmathcal%7BX%7D%7D%24%20up%20to%20%24p%24%20bits%20of%20precision.%20The%20chaotic%20dynamics%20of%20the%20dyadic%20map%2C%20which%20seemed%20like%20a%20nuisance%2C%20turns%20out%20to%20be%20the%20precise%20mechanism%20we%20need%20to%20systematically%20access%20the%20desired%20information.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20The%20Algorithm%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20The%20algorithm%20itself%20is%20deceptively%20simple%20once%20you%20see%20the%20pattern%3A%0A%0A%20%20%20%20%3E%20**Encoding%20Algorithm%3A**%0A%20%20%20%20%3E%20Given%20a%20dataset%20%24%5Cmathcal%7BX%7D%20%3D%20%5C%7Bx_0%2C%20...%2C%20x_%7Bn-1%7D%5C%7D%24%20where%20%24x_i%20%5Cin%20%5B0%2C%201%5D%24%2C%20encode%20the%20dataset%20into%20%24%5Calpha%24%3A%0A%20%20%20%20%3E%0A%20%20%20%20%3E%201.%20Convert%20each%20number%20to%20binary%20with%20%24p%24%20bits%20of%20precision%20%24b_i%20%3D%20%5Ctext%7Bbin%7D_p(x_i)%24%20for%20%24i%3D0%2C%20...%2C%20n-1%24%0A%20%20%20%20%3E%202.%20Concatenate%20into%20a%20single%20binary%20string%20%24b%20%3D%20b_0%20%5Coplus%20%20...%20%5Coplus%20b_%7Bn-1%7D%24%0A%20%20%20%20%3E%203.%20Convert%20to%20decimal%20%24%5Calpha%20%3D%20%5Ctext%7Bdec%7D(b)%24%0A%0A%0A%20%20%20%20The%20result%20is%20a%20single%2C%20decimal%2C%20scalar%20number%20%24%5Calpha%24%20with%20%24np%24%20bits%20of%20precision%20that%20contains%20our%20entire%20dataset.%20We%20can%20now%20discard%20%24%5Cmathcal%7BX%7D%24%20entirely.%0A%0A%20%20%20%20%3E%20**Decoding%20Algorithm%3A**%0A%20%20%20%20%3E%20Given%20sample%20index%20%24i%20%5Cin%20%5C%7B0%2C%20...%2C%20n-1%5C%7D%24%20and%20the%20encoded%20number%20%24%5Calpha%24%2C%20recover%20sample%20%24%5Ctilde%7Bx_i%7D%24%3A%0A%20%20%20%20%3E%0A%20%20%20%20%3E%201.%20Apply%20the%20dyadic%20map%20%24%5Cmathcal%7BD%7D%24%20exactly%20%24ip%24%20times%20%24%5Ctilde%7Bx%7D'_i%20%3D%20%5Cmathcal%7BD%7D%5E%7Bip%7D(%5Calpha)%20%3D%20(2%5E%7Bip%7D%20%5Calpha)%20%5Cmod%201%24%20%0A%20%20%20%20%3E%202.%20Extract%20the%20first%20%24p%24%20bits%20of%20%24%5Ctilde%7Bx%7D'_i%24's%20binary%20representation%20%24b_i%20%3D%20%5Ctext%7Bbin%7D_p(%5Ctilde%7Bx%7D'_i)%24%0A%20%20%20%20%3E%203.%20Covert%20to%20decimal%20%24%5Ctilde%7Bx%7D_i%20%3D%20%5Ctext%7Bdec%7D(b_i)%24%0A%0A%0A%20%20%20%20Mathematically%2C%20we%20can%20express%20these%20two%20algorithms%20with%20an%20encoder%20function%20%24g%3A%20%5B0%2C%201%5D%5En%20%5Cto%20%5B0%2C%201%5D%24%20that%20compresses%20the%20dataset%20and%20a%20decoder%20function%20%24f%3A%20%5Coverbrace%7B%5B0%2C%201%5D%7D%5E%7B%5Calpha%7D%20%5Ctimes%20%5Coverbrace%7B%5Cmathbb%7BZ%7D_%2B%7D%5E%7Bp%7D%20%5Ctimes%20%5Coverbrace%7B%5Bn%5D%7D%5Ei%20%5Cto%20%5B0%2C%201%5D%24%20that%20extracts%20individual%20data%20points%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Calpha%0A%20%20%20%20%26%3D%0A%20%20%20%20g(p%2C%20%5Cmathcal%7BX%7D)%20%3A%3D%20%5Ctext%7Bdec%7D%20%5CBig(%20%5Cbigoplus_%7Bx_i%20%5Cin%20%5Cmathcal%7BX%7D%7D%20%5Ctext%7Bbin%7D_p(x_i)%20%5CBig)%0A%20%20%20%20%5Ctag%7B4%7D%0A%20%20%20%20%5C%5C%0A%20%20%20%20%5Ctilde%7Bx%7D_i%0A%20%20%20%20%26%3D%0A%20%20%20%20f_%7B%5Calpha%2C%20p%7D(i)%20%3A%3D%20%5Ctext%7Bdec%7D%20%5CBig(%20%5Ctext%7Bbin%7D_p%20%5CBig(%20%5Cmathcal%7BD%7D%5E%7Bip%7D(%5Calpha)%20%5CBig)%20%5CBig)%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20%24%5Coplus%24%20means%20concatenation.%0A%0A%20%20%20%20The%20precision%20parameter%20%24p%24%20controls%20the%20trade-off%20between%20accuracy%20and%20storage%20efficiency.%20The%20larger%20%24p%24%20is%2C%20the%20more%20accurately%20our%20encoding%2C%20but%20the%20more%20storage%20it%20takes%20up.%20Our%20error%20bound%20is%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%7C%5Ctilde%7Bx%7D_i%20-%20x_i%20%7C%20%3C%20%5Cfrac%7B1%7D%7B2%5Ep%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20because%20we%20don't%20encode%20anything%20after%20the%20first%20%24p%24%20bits%20of%20precision.%0A%0A%20%20%20%20What%20makes%20this%20profound%20is%20the%20realization%20that%20we're%20not%20really%20%22learning%22%20anything%20in%20any%20conventional%20sense.%20We're%20encoding%20it%20directly%20into%20the%20bits%20of%20a%20real%20number%2C%20exploiting%20it's%20infinite%20precision%2C%20and%20then%20using%20the%20dyadic%20map%20to%20navigate%20through%20that%20number%20and%20extract%20exactly%20what%20we%20need%2C%20when%20we%20need%20it.%0A%0A%20%20%20%20From%20this%20perspective%2C%20the%20dyadic%20map%20resembles%20a%20classical%20ML%20model%20where%20the%20encoder%20%24g%24%20acts%20as%20%60model.fit()%60%20and%20the%20decoder%20%24f%24%20acts%20as%20%60model.predict()%60.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20Applying%20Some%20Makeup%0A%0A%20%20%20%20%3E%20%22You%20don%E2%80%99t%20want%20to%20overdo%20it%20with%20too%20much%20makeup%22%20-%20Heidi%20Klum%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20How%20do%20we%20go%20from%20the%20ugly%2C%20discontinuous%20decoder%20function%0A%0A%20%20%20%20%24%24%0A%20%20%20%20f_%7B%5Calpha%2Cp%7D(i)%20%3A%3D%20%5Ctext%7Bdec%7D%20%5CBig(%20%5Ctext%7Bbin%7D_p%20%5CBig(%20%5Cmathcal%7BD%7D%5E%7Bip%7D(%5Calpha)%20%5CBig)%20%5CBig)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20to%20that%20beautiful%20function%20I%20promised%20you%20at%20the%20start%20of%20the%20blog%0A%0A%20%20%20%20%24%24%20f_%7B%5Calpha%2C%20p%7D(i)%0A%20%20%20%20%3D%0A%20%20%20%20%5Csin%5E2%20%5CBig(%0A%20%20%20%20%20%20%20%202%5E%7Bi%20p%7D%20%5Carcsin%5E2(%5Csqrt%7B%5Calpha%7D)%0A%20%20%20%20%5CBig)%0A%20%20%20%20%3F%0A%20%20%20%20%24%24%0A%0A%20%20%20%20In%20this%20section%20we%20will%20%22apply%20makeup%22%20to%20the%20first%20function%20to%20get%20it%20looking%20a%20bit%20closer%20to%20the%20second%20function.%20We%20will%20keep%20the%20same%20core%20logic%20but%20make%20the%20function%20more%20ascetically%20pleasing.%20To%20do%20this%2C%20we%20will%20need%20another%20one-dimensional%20chaotic%20system%2C%20the%20%5Blogistic%20map%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FLogistic_map).%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20Logistic%20Map%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20The%20logistic-map%20at%20%24r%3D4%24%20on%20the%20unit%20interval%20is%20defined%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Cmathcal%7BL%7D(a_L)%0A%20%20%20%20%26%3D%0A%20%20%20%204%20a_L%20(1%20-%20a_L)%0A%20%20%20%20%26%0A%20%20%20%20%5Cmathcal%7BL%7D%3A%20%5B0%2C%201%5D%20%5Cto%20%5B0%2C%201%5D%0A%20%20%20%20%5Ctag%7B6%7D%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20which%20seems%20quite%20different%20than%20the%20familiar%20dyadic%20map%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Cmathcal%7BD%7D(a_D)%0A%20%20%20%20%26%3D%0A%20%20%20%20(2%20a_D)%20%5Cmod%201%0A%20%20%20%20%26%0A%20%20%20%20%5Cmathcal%7BD%7D%3A%20%5B0%2C%201%5D%20%5Cto%20%5B0%2C%201%5D%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20One%20is%20a%20bit-shifting%20operation%2C%20the%20other%20is%20a%20smooth%20parabola%20that%20ecologists%20use%20to%20model%20population%20growth.%20(Note%3A%20previously%20%24a%24%20was%20the%20input%20to%20the%20dyadic%20map%20but%20from%20now%20on%20%24a_D%24%20will%20be%20the%20input%20to%20the%20dyadic%20map%20to%20differentiate%20it%20from%20%24a_L%24%2C%20the%20input%20to%20the%20logistic%20map.)%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.function%0Adef%20L(a)%3A%20return%204%20*%20a%20*%20(1%20-%20a)%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20plt)%3A%0A%20%20%20%20def%20_()%3A%0A%20%20%20%20%20%20%20%20a_values%20%3D%20np.linspace(0%2C%201%2C%20100)%0A%0A%20%20%20%20%20%20%20%20fig%2C%20ax%20%3D%20plt.subplots()%0A%20%20%20%20%20%20%20%20ax.scatter(a_values%2C%20D(a_values)%2C%20label%3D%22Dyadic%22%2C%20s%3D2)%0A%20%20%20%20%20%20%20%20ax.scatter(a_values%2C%20L(a_values)%2C%20label%3D%22Logistic%22%2C%20s%3D2)%0A%20%20%20%20%20%20%20%20ax.set_xlabel(r%22%24a%24%22)%0A%20%20%20%20%20%20%20%20ax.set_ylabel(r%22%24%5Cmathcal%7BD%7D(a)%24%20or%20%24%5Cmathcal%7BL%7D(a)%24%22)%0A%20%20%20%20%20%20%20%20ax.set_title(%22Logistic%20vs%20Dyadic%20Map%22)%0A%20%20%20%20%20%20%20%20ax.legend()%0A%20%20%20%20%20%20%20%20%23%20plt.show()%0A%20%20%20%20%20%20%20%20return%20fig%0A%0A%0A%20%20%20%20_()%0A%20%20%20%20return%0A%0A%0A%40app.function%0Adef%20logistic_orbit(a_L%2C%20k)%3A%0A%20%20%20%20orbits%20%3D%20%5Ba_L%5D%0A%20%20%20%20for%20_%20in%20range(k)%3A%0A%20%20%20%20%20%20%20%20orbits.append(L(orbits%5B-1%5D))%0A%20%20%20%20return%20orbits%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20orbit_1%20%3D%20logistic_orbit(0.5%2C%205)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20orbit_2%20%3D%20logistic_orbit(1%2F3%2C%205)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20orbit_3%20%3D%20logistic_orbit(0.431%2C%205)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20What%20does%20the%20logistic%20orbit%20%24(a_L%2C%20%5Cmathcal%7BL%7D%5E1(a_L)%2C%20%5Cmathcal%7BL%7D%5E2(a_L)%2C%20%5Cmathcal%7BL%7D%5E3(a_L)%2C%20%5Cmathcal%7BL%7D%5E4(a_L)%2C%20%5Cmathcal%7BL%7D%5E5(a_L))%24%20look%20like%3F%20Similar%20or%20different%20to%20the%20dyadic%20orbit%20%24(a_D%2C%20%5Cmathcal%7BD%7D%5E1(a_D)%2C%20%5Cmathcal%7BD%7D%5E2(a_D)%2C%20%5Cmathcal%7BD%7D%5E3(a_D)%2C%20%5Cmathcal%7BD%7D%5E4(a_D)%2C%20%5Cmathcal%7BD%7D%5E5(a_D))%24%3F%0A%0A%20%20%20%20*%20If%20%24a_L%20%3D%20a_D%20%3D%200.5%24%2C%20the%20logistic%20orbit%20is%20%24(0.5%2C%201.0%2C%200.0%2C%200.0%2C%200.0%2C%200.0)%24%20while%20the%20dyadic%20orbit%20is%20%24(0.5%2C%200.0%2C%200.0%2C%200.0%2C%200.0%2C%200.0)%24.%20Although%20the%20dyadic%20orbit%20is%20just%20all%20zeros%2C%20the%20logistic%20orbit%20actually%20has%20%241.0%24%20as%20the%20second%20number%20in%20the%20orbit.%0A%20%20%20%20*%20If%20%24a_L%20%3D%201%2F3%24%2C%20the%20logistic%20orbit%20is%20%24(0.333%2C%200.888%2C%200.395%2C%200.956%2C%200.168%2C%200.560)%24%20while%20the%20dyadic%20orbit%20is%20%24(0.333%2C%200.667%2C%200.333%2C%200.667%2C%200.333%2C%200.667)%24.%20While%20the%20dyadic%20orbit%20repeats%20in%20a%20simple%20pattern%2C%20the%20logistic%20orbit%20is%20seemingly%20patternless.%0A%20%20%20%20*%20If%20%24a_L%20%3D%200.43085467085%24%2C%20the%20logistic%20orbit%20is%20%24(0.431%2C%200.981%2C%200.075%2C%200.277%2C%200.800%2C%200.639)%24%20while%20the%20dyadic%20orbit%20is%20%24(0.431%2C%200.862%2C%200.724%2C%200.448%2C%200.897%2C%200.792)%24.%20Both%20orbits%20here%20seem%20totally%20random%20and%20chaotic%2C%20but%20each%20in%20their%20own%20way.%0A%0A%20%20%20%20The%20logistic%20and%20dyadic%20maps%20create%20orbits%20that%20look%20nothing%20alike!%0A%0A%20%20%20%20However%2C%20%5Btopological%20conjugacy%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FTopological_conjugacy)%20tells%20us%20these%20two%20maps%20are%20*actually*%20the%20same.%20Not%20similar.%20Not%20analgous.%20The%20same.%20They%20have%20identical%20orbits%2C%20the%20exact%20same%20chaotic%20trajectories%2C%20simply%20expressed%20in%20different%20coordinates.%20The%20logistic%20map%2C%20for%20all%20its%20smooth%20curves%20and%20elegant%20form%2C%20is%20actually%20doing%20discrete%20binary%20operations%20under%20the%20hood%2C%20just%20like%20the%20dyadic%20map%20(and%20vice%20versa).%20Formally%2C%20two%20functions%20are%20topologically%20conjugate%20if%20there%20exists%20a%20homeomorphism%2C%20fancy%20talk%20for%20a%20change%20of%20coordinates%2C%20that%20perfectly%20takes%20you%20from%20one%20map%20to%20another.%20The%20change%20of%20coordinates%20here%20is%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20a_L%20%3D%20%5Cphi(a_D)%20%26%3D%20%5Csin%5E2(2%20%5Cpi%20a_D)%0A%20%20%20%20%26%0A%20%20%20%20%5Cphi%3A%20%5B0%2C%201%5D%20-%3E%20%5B0%2C%201%5D%0A%20%20%20%20%5Ctag%7B7%7D%0A%20%20%20%20%5C%5C%0A%20%20%20%20a_D%0A%20%20%20%20%3D%0A%20%20%20%20%5Cphi%5E%7B-1%7D(a_L)%0A%20%20%20%20%26%3D%0A%20%20%20%20%5Cfrac%7B1%7D%7B2%20%5Cpi%7D%20%5Carcsin%20(%5Csqrt%7Ba_L%7D)%0A%20%20%20%20%26%0A%20%20%20%20%5Cphi%5E%7B-1%7D%3A%20%5B0%2C%201%5D%20-%3E%20%5B0%2C%201%5D%0A%20%20%20%20%5Ctag%7B8%7D%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20We%20can%20map%20any%20%24a_L%24%20to%20an%20%24a_D%24%20and%20any%20%24a_D%24%20to%20an%20%24a_L%24.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20plt)%3A%0A%20%20%20%20def%20_()%3A%0A%20%20%20%20%20%20%20%20a_values%20%3D%20np.linspace(0%2C%201%2C%20100)%0A%20%20%20%20%20%20%20%20def%20phi(a)%3A%20return%20np.sin(2%20*%20np.pi%20*%20a)%20**%202%0A%20%20%20%20%20%20%20%20def%20phi_inverse(a)%3A%20return%20np.arcsin(np.sqrt(a))%20%2F%20(2.0%20*%20np.pi)%0A%0A%20%20%20%20%20%20%20%20fig%2C%20ax%20%3D%20plt.subplots()%0A%20%20%20%20%20%20%20%20ax.scatter(a_values%2C%20phi(a_values)%2C%20label%3D%22phi%22%2C%20s%3D2%2C%20c%3D%22g%22)%0A%20%20%20%20%20%20%20%20ax.scatter(a_values%2C%20phi_inverse(a_values)%2C%20label%3D%22phi%20inverse%22%2C%20s%3D2%2C%20c%3D%22r%22)%0A%20%20%20%20%20%20%20%20ax.set_xlabel(%22a%22)%0A%20%20%20%20%20%20%20%20ax.set_ylabel(%22output%22)%0A%20%20%20%20%20%20%20%20ax.set_title(%22phi%20and%20phi%20inverse%22)%0A%20%20%20%20%20%20%20%20ax.legend()%0A%20%20%20%20%20%20%20%20%23%20plt.show()%0A%20%20%20%20%20%20%20%20return%20fig%0A%0A%20%20%20%20_()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20Looking%20at%20the%20plot%2C%20the%20function%20%24%5Cphi%24%20has%20a%20period%20of%201%2C%20meaning%20it%20repeats%20the%20same%20values%20every%20time%20%24a_D%24%20increases%20by%20%241%24.%20This%20periodicity%20is%20crucial%20because%20it%20allows%20us%20to%20drop%20the%20modulo%20operation%20from%20the%20dyadic%20map%20%24%5Cmathcal%7BD%7D(a_D)%20%3D%20(2%20a_D)%20%5Cmod%201%24%20when%20transforming%20from%20the%20dyadic%20space%20to%20the%20logistic%20space.%20Formally%2C%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Cphi(a_D%20%5Cmod%201)%20%3D%20%5Cphi(a_D)%0A%20%20%20%20%5Ctag%7B9%7D%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20which%20will%20be%20important%20later%20on.%20To%20go%20back%20and%20forth%20between%20the%20dyadic%20and%20logistic%20maps%2C%20we%20apply%20%24%5Cphi%24%20to%20the%20output%20%24%5Cmathcal%7BD%7D%24%20and%20get%20%24%5Cmathcal%7BL%7D%24%3B%20we%20can%20also%20apply%20%24%5Cphi%5E%7B-1%7D%24%20to%20the%20input%20%24a_L%24%20to%20get%20%24%5Cmathcal%7BD%7D%24.%20Mathemtically%2C%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Cmathcal%7BL%7D(a_L)%0A%20%20%20%20%26%3D%0A%20%20%20%20%5Cphi(%5Cmathcal%7BD%7D(a_D))%0A%20%20%20%20%5C%5C%0A%20%20%20%20%5Cmathcal%7BD%7D(a_D)%0A%20%20%20%20%26%3D%0A%20%20%20%20%5Cmathcal%7BL%7D(%5Cphi%5E%7B-1%7D(a_L))%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Here%20%24%5Cphi%24%20takes%20us%20to%20the%20logistic%20space%20and%20%24%5Cphi%5E%7B-1%7D%24%20takes%20us%20back%20to%20the%20dyadic%20space.%20This%20is%20astonishing!%20%24%5Cphi%24%20is%20just%20a%20sin%20wave%20squared%20and%20with%20a%20period%20of%20one.%20It's%20inverse%2C%20%24%5Cphi%5E%7B-1%7D%24%20is%20even%20weirder%20looking%20with%20an%20%24%5Carcsin%24.%20But%20somehow%20these%20functions%20allow%20us%20to%20bridge%20the%20two%20maps%20%24%5Cmathcal%7BD%7D%24%20and%20%24%5Cmathcal%7BL%7D%24!%0A%0A%20%20%20%20Moreover%2C%20%24%5Cphi%24%20and%20%24%5Cphi%5E%7B-1%7D%24%20perfectly%20relate%20*every*%20single%20point%20in%20the%20infinite%20orbits%20of%20%24%5Cmathcal%7BD%7D%24%20and%20%24%5Cmathcal%7BL%7D%24%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20(a_D%2C%20%5Cmathcal%7BD%7D%5E1(a_D)%2C%20%5Cmathcal%7BD%7D%5E2(a_D)%2C%20...)%20%3D%20(a_L%2C%20%5Cmathcal%7BL%7D%5E1(%5Cphi%5E%7B-1%7D((a_L))%2C%20%5Cmathcal%7BL%7D%5E2(%5Cphi%5E%7B-1%7D((a_L))%2C%20...)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20or%20it%20can%20be%20expressed%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20(a_L%2C%20%5Cmathcal%7BL%7D%5E1(a_L)%2C%20%5Cmathcal%7BL%7D%5E2(a_L)%2C%20...)%20%3D%20(a_D%2C%20%5Cphi(%5Cmathcal%7BD%7D%5E1(a_D))%2C%20%5Cphi(%5Cmathcal%7BD%7D%5E2(a_D))%2C%20...)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20depending%20on%20if%20we%20want%20to%20be%20natively%20using%20the%20coordinate%20system%20of%20%24%5Cmathcal%7BD%7D%24%20or%20%24%5Cmathcal%7BL%7D%24.%20What%20appears%20as%20chaos%20in%20one%20coordinate%20system%20manifests%20as%20the%20exact%20same%20chaos%20in%20the%20other%2C%20*no%20matter%20how%20many%20iterations%20we%20apply*.%20Mathematically%2C%20this%20suggests%20something%20stronger%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Cmathcal%7BL%7D%5Ek(a_L)%0A%20%20%20%20%26%3D%0A%20%20%20%20%5Cphi(%5Cmathcal%7BD%7D%5Ek(a_D))%0A%20%20%20%20%5Ctag%7B10%7D%0A%20%20%20%20%5C%5C%0A%20%20%20%20%5Cmathcal%7BD%7D%5Ek(a_D)%0A%20%20%20%20%26%3D%0A%20%20%20%20%5Cmathcal%7BL%7D%5Ek(%5Cphi%5E%7B-1%7D(a_L))%0A%20%20%20%20%5Ctag%7B11%7D%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Think%20of%20these%20two%20orbits%20existing%20in%20parallel%20universes%20with%20%24%5Cphi%24%20and%20%24%5Cphi%5E%7B-1%7D%24%20acting%20as%20the%20bridges%20between%20%24%5Cmathcal%7BD%7D%24%20and%20%24%5Cmathcal%7BL%7D%24.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fix_marimo_path%2C%20mo)%3A%0A%20%20%20%20topological_conjugacy_image%20%3D%20mo.image(%0A%20%20%20%20%20%20%20%20fix_marimo_path(%22public%2Fimages%2Ftopological_conjugacy.png%22)%2C%0A%20%20%20%20%20%20%20%20width%3D400%2C%0A%20%20%20%20%20%20%20%20caption%3D%22Topological%20conjugacy%20between%20the%20dyadic%20and%20logistic%20map.%22%2C%0A%20%20%20%20%20%20%20%20style%3D%7B%22display%22%3A%20%22block%22%2C%20%22margin%22%3A%20%220%20auto%22%7D%0A%20%20%20%20)%0A%20%20%20%20topological_conjugacy_image%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20We%20can%20now%20revist%20the%20dyadic%20and%20logistic%20orbits%20when%20%24a_D%20%3D%20a_L%20%3D%200.431%24.%0A%0A%20%20%20%20*%20When%20%24a_D%20%3D%20a_L%20%3D%200.431%24%2C%20we%20know%20the%20**dyadic%20orbit**%20is%20%24(0.431%2C%200.862%2C%200.724%2C%200.448%2C%200.897%2C%200.792)%24.%20If%20we%20apply%20%24%5Cphi%24%20to%20every%20output%20element%20%24%5Cphi(%5Cmathcal%7BD%7D%5Ek(a_D))%24%2C%20we%20get%20%24(0.431%2C%200.981%2C%200.075%2C%200.277%2C%200.800%2C%200.639)%24.%20This%20is%20exactly%20the%20logistic%20orbit%20%20we%20saw%20in%20eqn.%20(10)!%0A%20%20%20%20*%20When%20%24a_D%20%3D%20a_L%20%3D%200.431%24%2C%2C%20we%20know%20the%20**logistic%20orbit**%20%24(0.431%2C%200.981%2C%200.075%2C%200.277%2C%200.800%2C%200.639)%24.%20If%20we%20apply%20%24%5Cphi%5E%7B-1%7D%24%0A%20%20%20%20to%20every%20input%20element%20before%20the%20logistic%20map%20%24%5Cmathcal%7BL%7D(%5Cphi%5E%7B-1%7D(a_L)))%24%20we%20get%20the%20dyadic%20orbit%20%24(0.431%2C%200.862%2C%200.724%2C%200.448%2C%200.897%2C%200.792)%24.%0A%0A%20%20%20%20We%20see%20that%20although%20both%20these%20orbits%20look%20completly%20unrelated%2C%20these%20two%20orbits%20are%20perfectly%20connected%20to%20one%20another%20through%20%24%5Cphi%24%20and%20%24%5Cphi%5E%7B-1%7D%24.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20A%20New%20Algorithm%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20**Can%20we%20use%20the%20topological%20conjugacy%20of%20%24%5Cmathcal%7BD%7D%24%20and%20%24%5Cmathcal%7BL%7D%24%20as%20makeup%3F**%0A%0A%20%20%20%20While%20%24%5Cmathcal%7BD%7D%24%20is%20ugly%20and%20discontinuous%2C%20%24%5Cmathcal%7BL%7D%24%20is%20smooth%20and%20differentiable.%20We%20can%20use%20the%20logistic%20map%20as%20%22makeup%22%20to%20hide%20the%20crude%20dyadic%20operations.%20We%20want%20our%20decoder%20to%20use%20%24%5Cmathcal%7BL%7D%24%20instead%20of%20%24%5Cmathcal%7BD%7D%24.%20But%20for%20the%20encoder%20to%20glue%20together%20the%20bits%20of%20our%20dataset%2C%20we%20needs%20to%20be%20in%20the%20dyadic%20space%20so%20our%20clever%20bit%20manipulations%20will%20still%20work%20out.%20Here's%20the%20strategy%3A%0A%0A%20%20%20%201.%20Encoder%3A%20Work%20in%20dyadic%20space%20where%20bit%20manipulation%20works%20(use%20%24%5Cphi%24)%20but%20output%20parameter%20in%20logistic%20space%20(use%20%24%5Cphi%5E%7B-1%7D%24)%0A%20%20%20%202.%20Decoder%3A%20Work%20entirely%20in%20smooth%20logistic%20space%20using%20the%20conjugacy%20relationship%0A%0A%20%20%20%20This%20gives%20us%20two%20new%20beautiful%20encoder%2Fdecoder%20algorithms%20where%20the%20main%20changes%20are%20bolded%3A%0A%0A%20%20%20%20%3E%20**Encoding%20Algorithm%3A**%0A%20%20%20%20%3E%20Given%20a%20dataset%20%24%5Cmathcal%7BX%7D%20%3D%20%5C%7Bx_0%2C%20...%2C%20x_n%5C%7D%24%20where%20%24x_i%20%5Cin%20%5B0%2C%201%5D%24%2C%20encode%20the%20dataset%20into%20%24a_L%24%3A%0A%20%20%20%20%3E%0A%20%20%20%20%3E%201.%20***Transform%20data%20to%20dyadic%20coordinates%3A%20%24z_i%20%3D%20%5Cphi%5E%7B-1%7D(x_i)%20%3D%20%5Cfrac%7B1%7D%7B2%20%5Cpi%7D%20%5Carcsin%E2%81%A1(%20x_i%20)%24%20for%20%24i%3D1%2C%20...%2C%20n%24***%0A%20%20%20%20%3E%202.%20Convert%20each%20transformed%20number%20to%20binary%20with%20%24p%24%20bits%20of%20precision%3A%20%24b_i%20%3D%20%5Ctext%7Bbin%7D_p(z_i)%24%20for%20%24i%3D1%2C%20...%2C%20n%24%0A%20%20%20%20%3E%203.%20Concatenate%20into%20a%20single%20binary%20string%20%24b%20%3D%20b_0%20%5Coplus%20%20...%20%5Coplus%20b_n%24%0A%20%20%20%20%3E%204.%20Convert%20to%20decimal%20%24a_D%20%3D%20%5Ctext%7Bdec%7D(b)%24%0A%20%20%20%20%3E%205.%20***Transform%20to%20logistic%20space%3A%20%24%5Calpha%20%3D%20a_L%20%3D%20%5Cphi(a_D)%20%3D%20%5Csin%5E2(2%20%5Cpi%20a_D)%24***%0A%0A%20%20%20%20The%20result%20is%20a%20single%2C%20decimal%2C%20scalar%20number%20%24%5Calpha%24%20with%20%24np%24%20bits%20of%20precision%20that%20contains%20our%20entire%20dataset.%20We%20can%20now%20discard%20%24%5Cmathcal%7BX%7D%24%20entirely.%0A%0A%20%20%20%20%3E%20**Decoding%20Algorithm%3A**%0A%20%20%20%20%3E%20Given%20sample%20index%20%24i%24%20and%20the%20encoded%20number%20%24%5Calpha%24%2C%20recover%20sample%20%24%5Ctilde%7Bx_i%7D%24%3A%0A%20%20%20%20%3E%0A%20%20%20%20%3E%201.%20***Apply%20the%20logistic%20map%20%24%5Cmathcal%7BL%7D%24%20exactly%20%24ip%24%20times%20%24%5Ctilde%7Bx%7D'_i%20%3D%20%5Cmathcal%7BL%7D%5E%7Bip%7D(%5Calpha)%20%3D%20%5Csin%5E2%20%5CBig(2%5E%7Bi%20p%7D%20%5Carcsin%5E2(%5Csqrt%7B%5Calpha%7D)%20%5CBig)%24***%0A%20%20%20%20%3E%202.%20Extract%20the%20first%20%24p%24%20bits%20of%20%24%5Ctilde%7Bx%7D'_i%24's%20binary%20representation%20%24b_i%20%3D%20%5Ctext%7Bbin%7D_p(%5Ctilde%7Bx%7D'_i)%24%0A%20%20%20%20%3E%203.%20Covert%20to%20decimal%20%24%5Ctilde%7Bx%7D_i%20%3D%20%5Ctext%7Bdec%7D(b_i)%24%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20Mathematically%2C%20we%20can%20express%20this%20with%20a%20new%20and%20improved%20encoder%20%24g%24%20and%20decoder%20%24f%24%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Calpha%0A%20%20%20%20%26%3D%0A%20%20%20%20g(p%2C%20%5Cmathcal%7Bx%7D)%20%3A%3D%20%5Cphi%20%5Cbigg(%20%5Ctext%7Bdec%7D%20%5CBig(%20%5Cbigoplus_%7Bx%20%5Cin%20%5Cmathcal%7BX%7D%7D%20%5Ctext%7Bbin%7D_p(%5Cphi%5E%7B-1%7D(x))%20%5CBig)%20%5Cbigg)%0A%20%20%20%20%5C%5C%0A%20%20%20%20%5Ctilde%7Bx%7D_i%0A%20%20%20%20%26%3D%0A%20%20%20%20f_%7B%5Calpha%2Cp%7D(i)%0A%20%20%20%20%3A%3D%0A%20%20%20%20%5Ctext%7Bdec%7D%20%5CBig(%20%5Ctext%7Bbin%7D_p%20%5CBig(%20%5Cmathcal%7BL%7D%5E%7Bip%7D(%5Calpha)%20%5CBig)%20%5CBig)%0A%20%20%20%20%3D%0A%20%20%20%20%5Ctext%7Bdec%7D%20%5CBig(%20%5Ctext%7Bbin%7D_p%20%5CBig(%20%5Csin%5E2%20%5CBig(2%5E%7Bip%7D%20%5Carcsin(%5Csqrt%7B%5Calpha%7D)%20%5CBig)%20%5CBig)%20%5CBig)%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20%24%5Coplus%24%20means%20concatenation.%20The%20decoder%20here%20is%20tantalizingly%20close%20to%20the%20function%20I%20promised%20at%20the%20start%3A%0A%0A%20%20%20%20%24%24%20f_%7B%5Calpha%2C%20p%7D(i)%0A%20%20%20%20%3D%0A%20%20%20%20%5Csin%5E2%20%5CBig(%0A%20%20%20%20%20%20%20%202%5E%7Bx%20p%7D%20%5Carcsin%5E2(%5Csqrt%7B%5Calpha%7D)%0A%20%20%20%20%5CBig)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20but%20is%20still%20wrapped%20with%20those%20pesky%20%24%5Ctext%7Bdec%7D%24%20and%20%24%5Ctext%7Bbin%7D_p%24%20operations.%20However%2C%20something%20profound%20has%20happened%20here.%20We've%20taken%20the%20crude%2C%20discontinuous%20dyadic%20map%20and%20transformed%20it%20into%20something%20smooth%20and%20differentiable.%20The%20logistic%20map%20doesn't%20*look*%20like%20it's%20doing%20binary%20operations%2C%20but%20underneath%20the%20elegant%20trigonometry%2C%20it's%20performing%20exactly%20the%20same%20bit%20manipulations%20as%20its%20topological%20coungant%2C%20the%20dyadic%20map.%20Indeed%2C%20the%20makeup%20looks%20pretty%20great!%0A%0A%20%20%20%20However%2C%20nothing%20is%20free.%20The%20cost%20of%20using%20the%20logistic%20map%20instead%20of%20the%20dyadic%20map%20is%20that%20our%20error%20is%20now%20%242%20%5Cpi%24%20times%20larger%2C%20%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%7C%5Ctilde%7Bx%7D_i%20-%20x_i%20%7C%20%5Cleq%20%5Cfrac%7B2%20%5Cpi%7D%7B2%5E%7Bp%7D%7D%20%3D%20%5Cfrac%7B%5Cpi%7D%7B2%5E%7Bp-1%7D%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20We%20get%20this%20%242%20%5Cpi%24%20factor%20by%20noting%20that%20the%20derivative%20of%20%24%5Cphi%24%20is%20bounded%20by%20%242%20%5Cpi%24%20and%20applying%20the%20mean-value%20theorem.%20For%20a%20proof%2C%20see%20section%202.5%20of%20%22Real%20numbers%2C%20data%20science%20and%20chaos%3A%20How%20to%20fit%20any%20dataset%20with%20a%20single%20parameter%22.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20How%20did%20we%20get%20%24%5Cmathcal%7BL%7D%5E%7Bip%7D(%5Calpha)%20%3D%20%5Csin%5E2%20%5CBig(2%5E%7Bi%20p%7D%20%5Carcsin%5E2(%5Csqrt%7B%5Calpha%7D)%20%5CBig)%24%3F%0A%0A%20%20%20%20We%20just%20need%20to%20perform%20some%20simple%20algebraic%20manipulation%20with%20our%20equations%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Cmathcal%7BL%7D%5Ek(%5Calpha)%0A%20%20%20%20%26%3D%0A%20%20%20%20%5Cmathcal%7BL%7D%5Ek(a_L)%0A%20%20%20%20%26%0A%20%20%20%20%5Ctext%7Bby%20%24%5Calpha%20%3D%20a_L%24%7D%0A%20%20%20%20%5C%5C%0A%20%20%20%20%26%3D%0A%20%20%20%20%5Cphi(%5Cmathcal%7BD%7D%5Ek(a_D))%0A%20%20%20%20%26%0A%20%20%20%20%5Ctext%7Bby%20%24(10)%24%7D%0A%20%20%20%20%5C%5C%0A%20%20%20%20%26%3D%0A%20%20%20%20%5Cphi((2%5Ek%20a_D)%20%5Cmod%201)%0A%20%20%20%20%26%0A%20%20%20%20%5Ctext%7Bby%20%24(3)%24%7D%0A%20%20%20%20%5C%5C%0A%20%20%20%20%26%3D%0A%20%20%20%20%5Cphi(2%5Ek%20a_D)%0A%20%20%20%20%26%0A%20%20%20%20%5Ctext%7Bby%20%24(9)%24%7D%0A%20%20%20%20%5C%5C%0A%20%20%20%20%26%3D%0A%20%20%20%20%5Csin%5E2(2%20%5Cpi%20%5Ccdot%20(2%5Ek%20a_D))%0A%20%20%20%20%26%0A%20%20%20%20%5Ctext%7Bby%20%24(7)%24%7D%0A%20%20%20%20%5C%5C%0A%20%20%20%20%26%3D%0A%20%20%20%20%5Csin%5E2%20%5Cbigg(2%20%5Cpi%202%5Ek%20%5CBig(%20%5Cfrac%7B1%7D%7B2%20%5Cpi%7D%20%5Carcsin(%5Csqrt%7Ba_L%7D)%20%5CBig)%20%5Cbigg)%0A%20%20%20%20%26%0A%20%20%20%20%5Ctext%7Bby%20%24(8)%24%7D%0A%20%20%20%20%5C%5C%0A%20%20%20%20%26%3D%0A%20%20%20%20%5Csin%5E2%20%5CBig(2%5Ek%20%5Carcsin(%5Csqrt%7Ba_L%7D)%20%5CBig)%0A%20%20%20%20%26%0A%20%20%20%20%5Ctext%7Bby%20simplification%7D%0A%20%20%20%20%5C%5C%0A%20%20%20%20%26%3D%0A%20%20%20%20%5Csin%5E2%20%5CBig(2%5Ek%20%5Carcsin(%5Csqrt%7B%5Calpha%7D)%20%5CBig)%0A%20%20%20%20%26%0A%20%20%20%20%5Ctext%7Bby%20%24%5Calpha%20%3D%20a_L%24%7D%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%20Code%20Implementation%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20Now%20comes%20the%20moment%20of%20truth.%20We've%20built%20up%20all%20this%20beautiful%20math%20about%20chaos%20theory%20and%20topological%20conjugacy%2C%20but%20can%20we%20actually%20code%20it%20up%3F%0A%0A%20%20%20%20If%20you've%20been%20paying%20attention%2C%20there%20is%20one%20crucial%20implementation%20detail%20we%20have%20to%20worry%20about.%20If%20our%20dataset%20%24%5Cmathcal%7BX%7D%24%20has%20%24n%24%20samples%2C%20each%20encoded%20with%20%24p%24%20bits%2C%20%24%5Calpha%24%20will%20contain%20%24np%24%20bits.%20For%20ARC-AGI-2%20with%20hundreds%20of%20tasks%20and%20high%20precision%2C%20this%20could%20be%20millions%20of%20bits.%20Standard%20computers%20can%20only%20handle%20numbers%20with%2032%20or%2064%20bits.%20How%20do%20we%20even%20store%20%24%5Calpha%24%2C%20much%20less%20solve%20ARC-AGI-2%20with%20it%3F%20%0A%0A%20%20%20%20The%20answer%20is%20simple%3A%20we%20can%20use%20an%20arbitrary%20precision%20arithmetic%20library%20like%20%5Bmpmath%5D(%5Bhttps%3A%2F%2Fgithub.com%2Faleaxit%2Fgmpy%5D(https%3A%2F%2Fgithub.com%2Fmpmath%2Fmpmath))%20that%20can%20represent%20numbers%20with%20as%20many%20bits%20as%20we%20want.%20Instead%20of%20a%20regular%20Python%20float%2C%20we%20represent%20%24%5Calpha%24%20as%20a%20mpmath%20float%20with%20%24np%24%20bits%20of%20precision.%20We%20then%20run%20the%20decoder%20with%20mpmath%20operations%20and%20convert%20the%20final%20result%20back%20to%20a%20regular%20Python%20float.%20Note%3A%20operations%20with%20arbitrary%20precision%20arithmetic%20libraries%20like%20mpmath%20tend%20to%20be%20*significantly*%20slower%20than%20regular%20floating%20point%20operations.%0A%0A%20%20%20%20But%20mpmath%20gives%20us%20another%20gift%3A%20it%20actually%20removes%20the%20pesky%20%24%5Ctext%7Bdec%7D(%5Ctext%7Bbin%7D_p(%5Ccdot))%24%20operations%20from%20our%20decoder%0A%0A%20%20%20%20%24%24%20f_%7B%5Calpha%2C%20p%7D(i)%0A%20%20%20%20%3D%0A%20%20%20%20%5Ctext%7Bdec%7D%20%5CBig(%20%5Ctext%7Bbin%7D_p%20%5CBig(%20%5Cmathcal%7BL%7D%5E%7Bip%7D(%5Calpha)%20%5CBig)%20%5CBig).%0A%20%20%20%20%24%24%0A%0A%20%20%20%20In%20our%20implementation%2C%20we%20use%20%24%5Ctext%7Bdec%7D(%5Ctext%7Bbin%7D_p(%5Ccdot))%24%20to%20truncate%20%24%5Cmathcal%7BL%7D%5E%7Bip%7D(%5Calpha)%24%20to%20exactly%20%24p%24%20bits%20and%20then%20we%20convert%20%24f_%7B%5Calpha%2C%20p%7D(i)%24%20from%20a%20%24p%24-bit%20mpmath%20number%20to%20a%20Python%20float32.%20During%20this%20conversion%2C%20Python%20copies%20the%20first%20%24p%24%20bits%20of%20%24f_%7B%5Calpha%2C%20p%7D(i)%24%20%20and%20then%20fills%20the%20remaining%20bits%20of%20the%20Python%20float32%20(bits%20%24p%2B1%24%20through%20%2432%24)%20with%20random%20meaningless%20junk%20bits%20(assuming%20%24p%3C%3D32%24).%20Since%20our%20model%20only%20guarantees%20accuracy%20for%20the%20first%20%24p%24%20bits%2C%20these%20random%20bits%20don't%20matter.%0A%0A%20%20%20%20However%2C%20converting%20to%20binary%20and%20back%20is%20wildly%20expensive%2C%20especially%20when%20%24%5Calpha%24%20contains%20millions%20of%20bits.%20Upon%20taking%20a%20closer%20look%2C%20we%20can%2C%20in%20fact%2C%20actually%20skip%20the%20entire%20%24%5Ctext%7Bdec%7D(%5Ctext%7Bbin%7D_p(%5Ccdot))%24%20step%20and%20convert%20%24%5Cmathcal%7BL%7D%5E%7Bip%7D(%5Calpha)%24%20directly%20to%20a%20Python%20float32.%20The%20first%20%24p%24%20bits%20of%20%24%5Cmathcal%7BL%7D%5E%7Bip%7D(%5Calpha)%24%20still%20get%20copied%20correctly%20and%20bits%20%24p%2B1%24%20through%20%2432%24%20get%20filled%20with%20the%20higher-order%20bits%20of%20%24%5Cmathcal%7BL%7D%5E%7Bip%7D(%5Calpha)%24%20instead%20of%20random%20Python%20bits.%20Since%20our%20prediction%20only%20uses%20the%20first%20%24p%24%20bits%2C%20these%20extra%20bits%20are%20irrelevant%20whether%20they%20come%20from%20Python%20or%20straight%20from%20our%20decoder%20%24%5Cmathcal%7BL%7D%5E%7Bip%7D(%5Calpha)%24.%20Now%20we%20can%20get%20the%20correct%20answer%20without%20the%20expensive%20%24%5Ctext%7Bdec%7D(%5Ctext%7Bbin%7D_p(%5Ccdot))%24%20operation%20since%20the%20bits%20%24p%2B1%24%20through%20%2432%24%20are%20disregarded%20and%20can%20come%20from%20anywhere.%20Removing%20%24%5Ctext%7Bdec%7D(%5Ctext%7Bbin%7D_p(%5Ccdot))%24%2C%20our%20decoder%20simplifies%20to%20exactly%20what%20we%20promised%20at%20the%20start%3A%0A%0A%20%20%20%20%24%24%20f_%7B%5Calpha%2C%20p%7D(i)%0A%20%20%20%20%3D%0A%20%20%20%20%5Cmathcal%7BL%7D%5E%7Bip%7D(%5Calpha)%0A%20%20%20%20%3D%0A%20%20%20%20%5Csin%5E2%20%5CBig(%0A%20%20%20%20%20%20%20%202%5E%7Bx%20p%7D%20%5Carcsin%5E2(%5Csqrt%7B%5Calpha%7D)%0A%20%20%20%20%5CBig)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20This%20is%20amazing!%20Usually%20translating%20math%20into%20code%20turns%20beautiful%20theory%20into%20ugly%2C%20complicated%20messes.%20But%20surprisingly%2C%20leveraging%20mpmath%20has%20the%20opposite%20effect%20and%20actually%20makes%20our%20decoder%20even%20simpler.%20Now%20let's%20get%20to%20the%20code!%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20Building%20Blocks%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22First%2C%20we%20need%20to%20import%20our%20arbitrary-precision%20math%20library%2C%20mpmath.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20from%20mpmath%20import%20mp%2C%20asin%20as%20Arcsin%2C%20sqrt%20as%20Sqrt%2C%20sin%20as%20Sin%2C%20pi%20as%20Pi%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20Arcsin%2C%20Pi%2C%20Sin%2C%20Sqrt%2C%20mp%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22We%20need%20some%20functions%20to%20convert%20from%20binary%20to%20decimal%20and%20back.%20We%20cannot%20simply%20use%20python's%20%60bin%60%20function%20because%20it%20only%20converts%20integers%20to%20binary%20and%20we%20have%20floats%20in%20%24%5B0%2C%201%5D%24.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20np)%3A%0A%20%20%20%20def%20dyadic_map(X%3Anp.ndarray)%3A%20return%20(2%20*%20X)%20%25%201%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20(dyadic_map%2C)%0A%0A%0A%40app.cell%0Adef%20_(dyadic_map%2C%20mo%2C%20np)%3A%0A%20%20%20%20def%20decimal_to_binary(x_decimal%3Anp.ndarray%7Cfloat%7Cint%7Clist%7Ctuple%2C%20precision%3Aint)%3A%0A%20%20%20%20%20%20%20%20%23%20converts%20a%201D%20sequence%20from%20decimal%20to%20binary%2C%20assume%20all%20values%20in%20%5B0%2C%201%5D%0A%20%20%20%20%20%20%20%20if%20isinstance(x_decimal%2C%20(float%2C%20int))%3A%20x_decimal%20%3D%20np.array(%5Bx_decimal%5D%2C%20dtype%3Dfloat)%0A%20%20%20%20%20%20%20%20elif%20isinstance(x_decimal%2C%20(list%2C%20tuple))%3A%20x_decimal%20%3D%20np.array(x_decimal%2C%20dtype%3Dfloat)%0A%20%20%20%20%20%20%20%20%23%20elif%20isinstance(x_decimal%2C%20mp.mpf)%3A%20x_decimal%20%3D%20np.array(%5Bx_decimal%5D)%0A%20%20%20%20%20%20%20%20assert%200%20%3C%3D%20x_decimal.min()%20%3C%3D%20x_decimal.max()%20%3C%3D%201%2C%20f%22expected%20x_decimal%20to%20be%20in%20%5B0%2C%201%5D%20but%20got%20%5B%7Bx_decimal.min()%7D%2C%20%7Bx_decimal.max()%7D%5D%22%0A%20%20%20%20%20%20%20%20bits%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20for%20_%20in%20range(precision)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20bits.append(np.round(x_decimal))%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20bit%20%3D%20np.zeros_like(x_decimal)%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20bit%5Bx_decimal%20%3E%200.5%5D%20%3D%201%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20bits.append(bit)%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20print(f'%7Bx_decimal%3D%7D')%0A%20%20%20%20%20%20%20%20%20%20%20%20x_decimal%20%3D%20dyadic_map(x_decimal)%0A%20%20%20%20%20%20%20%20%23%20print(f'%7Bbits%3D%7D')%0A%20%20%20%20%20%20%20%20%23%20print('np(bits)%3D'%2C%20np.array(bits).astype(int).T.ravel())%0A%20%20%20%20%20%20%20%20return%20''.join(map(str%2C%20np.array(bits).astype(int).T.ravel()))%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20(decimal_to_binary%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20mp%2C%20np)%3A%0A%20%20%20%20def%20binary_to_decimal(x_binary%3Anp.ndarray)%3A%0A%20%20%20%20%20%20%20%20%23%20converts%20an%20arbitrary-precision%20scalar%20from%20binary%20to%20decimal%0A%20%20%20%20%20%20%20%20return%20mp.fsum(int(b)%20*%20mp.mpf(0.5)%20**%20(i%2B1)%20for%20i%2C%20b%20in%20enumerate(x_binary))%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20(binary_to_decimal%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Next%20we%20need%20%24%5Cphi%24%20and%20%24%5Cphi%5E%7B-1%7D%24%20to%20go%20back%20and%20forth%20between%20the%20dyadic%20and%20logistic%20spaces.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Pi%2C%20Sin%2C%20mo)%3A%0A%20%20%20%20def%20phi(x)%3A%20return%20Sin(2%20*%20Pi%20*%20x)%20**%202%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20(phi%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20np)%3A%0A%20%20%20%20def%20phi_inverse(x)%3A%20return%20np.arcsin(np.sqrt(x))%20%2F%20(2.0%20*%20np.pi)%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20(phi_inverse%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20We%20can%20now%20implement%20the%20logistic%20encoder%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Calpha%0A%20%20%20%20%3D%0A%20%20%20%20g(p%2C%20%5Cmathcal%7Bx%7D)%0A%20%20%20%20%3D%0A%20%20%20%20%5Cphi%20%5Cbigg(%20%5Ctext%7Bdec%7D%20%5CBig(%20%5Cbigoplus_%7Bx%20%5Cin%20%5Cmathcal%7BX%7D%7D%20%5Ctext%7Bbin%7D_p(%5Cphi%5E%7B-1%7D(x))%20%5CBig)%20%5Cbigg)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20in%20code%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(binary_to_decimal%2C%20decimal_to_binary%2C%20mo%2C%20mp%2C%20phi%2C%20phi_inverse)%3A%0A%20%20%20%20def%20logistic_encoder(X%2C%20p%2C%20full_precision)%3A%0A%20%20%20%20%20%20%20%20%23%20set%20the%20mpmath%20arbitrary%20precision%20before%20computing%20anything%0A%20%20%20%20%20%20%20%20mp.prec%20%3D%20full_precision%0A%0A%20%20%20%20%20%20%20%20%23%201.%20apply%20%CF%86%5E(-1)%20for%20all%20x%20in%20X%0A%20%20%20%20%20%20%20%20phi_inv_decimal_list%20%3D%20phi_inverse(X)%0A%0A%20%20%20%20%20%20%20%20%23%202.%20convert%20to%20binary%20for%20all%20x%20in%20X%0A%20%20%20%20%20%20%20%20phi_inv_binary_list%20%3D%20decimal_to_binary(phi_inv_decimal_list%2C%20p)%0A%0A%20%20%20%20%20%20%20%20%23%203.%20concatenate%20all%20binary%20strings%20together%20into%20a%20scalar%0A%20%20%20%20%20%20%20%20phi_inv_binary_scalar%20%3D%20''.join(phi_inv_binary_list)%0A%20%20%20%20%20%20%20%20if%20len(phi_inv_binary_scalar)%20!%3D%20full_precision%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(f%22Expected%20%7Bfull_precision%7D%20bits%20but%20got%20%7Blen(phi_inv_binary_scalar)%7D%20bits.%22)%0A%0A%20%20%20%20%20%20%20%20%23%204.%20convert%20to%20decimal%0A%20%20%20%20%20%20%20%20phi_inv_decimal_scalar%20%3D%20binary_to_decimal(phi_inv_binary_scalar)%0A%0A%20%20%20%20%20%20%20%20%23%205.%20apply%20%CF%86%0A%20%20%20%20%20%20%20%20alpha%20%3D%20phi(phi_inv_decimal_scalar)%0A%20%20%20%20%20%20%20%20return%20alpha%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20(logistic_encoder%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20We%20compute%20%24%5Calpha%24%20in%20five%20steps%20using%20mpmath%20with%20precision%20set%20to%20%24np%24%20bits.%20Crucially%2C%20step%204%20produces%20an%20mpmath%20float%20with%20the%20full%20%24np%24%20bits%20of%20precision%2C%20which%20we%20then%20transform%20in%20step%205%20to%20get%20our%20final%20%24np%24-bit%20parameter%20%24%5Calpha%24.%20Next%2C%20we%20implement%20the%20logistic%20decoder%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Ctilde%7Bx%7D_i%20%0A%20%20%20%20%3D%0A%20%20%20%20f_%7B%5Calpha%2C%20p%7D(i)%0A%20%20%20%20%3D%0A%20%20%20%20%5Csin%5E2%20%5CBig(%0A%20%20%20%20%20%20%20%202%5E%7Bx%20p%7D%20%5Carcsin%5E2(%5Csqrt%7B%5Calpha%7D)%0A%20%20%20%20%5CBig)%0A%20%20%20%20%24%24%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Arcsin%2C%20Sin%2C%20Sqrt%2C%20mo%2C%20mp)%3A%0A%20%20%20%20def%20logistic_decoder(alpha%2C%20full_precision%2C%20p%2C%20i)%3A%0A%20%20%20%20%20%20%20%20%23%20set%20the%20mpmath%20arbitrary%20precision%0A%20%20%20%20%20%20%20%20mp.prec%20%3D%20full_precision%0A%20%20%20%20%20%20%20%20return%20float(Sin(2%20**%20(i%20*%20p)%20*%20Arcsin(Sqrt(alpha)))%20**%202)%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20(logistic_decoder%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Again%2C%20we%20set%20the%20mpmath%20precision%20to%20%24np%24%20bits%20and%20implement%20the%20decoder%20in%20a%20single%20line%20using%20mpmath's%20arbitrary-precision%20functions%3A%20%60Sin%60%2C%20%60Arcsin%60%2C%20and%20%60Sqrt%60.%20That's%20it.%20Our%20entire%20encoder%20and%20decoder%2C%20the%20heart%20of%20our%20one-parameter%20model%2C%20is%20just%20a%20handful%20of%20lines%20and%20a%20bit%20of%20beautiful%20mathematics.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20Basic%20Implementation%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Let's%20put%20our%20%60logistic_encoder%60%20and%20%60logistic_decoder%60%20functions%20to%20the%20test%20and%20create%20a%20one-parameter%20model%20for%20the%20first%20task%20from%20ARC-AGI-2's%20public%20eval%20set.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(ds%2C%20plot_arcagi)%3A%0A%20%20%20%20plot_arcagi(ds%2C%20%22eval%22%2C%200)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20In%20this%20task%2C%20we%20have%204%20example%20input-output%20pairs%20and%20a%20question%20input-output%20pair%2C%20seperated%20by%20the%20vertical%20line.%20The%20challenge%3A%20given%20the%204%20examples%20and%20the%20question%20input%2C%20predict%20the%20question%20output%20by%20discovering%20the%20underlying%20pattern.%0A%0A%20%20%20%20Take%20a%20moment%20and%20see%20if%20you%20can%20spot%20it.%20It%20is%20quite%20hard.%0A%0A%20%20%20%20Remember%2C%20to%20an%20LLM%20this%20is%20just%20a%20grid%20of%20integers%20in%20%24%5B0%2C9%5D%24.%20We've%20just%20added%20colors%20to%20make%20it%20easier%20for%20humans%20to%20see%20the%20pattern.%20From%20an%20LLM's%20perspective%2C%20the%20outputs%20are%3A%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(ds%2C%20plot_arcagi)%3A%0A%20%20%20%20plot_arcagi(ds%2C%20%22eval%22%2C%200%2C%20show_nums%3D'outputs')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20To%20make%20the%20one-parameter%20model%20work%20for%20ARC-AGI-2%2C%20we%20need%20to%20make%20three%20additions%20to%20our%20encoder%2C%20decoder%20functions%3A%0A%0A%20%20%20%201.%20**Supervised%20learning.**%20ARC-AGI-2%20is%20a%20supervised%20learning%20problem%20with%20input-output%20pairs%20%24(X%2CY)%24%2C%20but%20our%20encoder%20can%20only%20handle%20unsupervised%20datasets%20%24(X)%24.%20We%20simply%20encode%20the%20outputs%20%24Y%24%20instead%20of%20the%20inputs%20%24X%24%20because%20the%20outputs%20%24Y%24%20are%20what%20we%20actually%20need%20to%20memorize.%0A%20%20%20%202.%20**Shape%20handling.**%20Our%20encoder%20works%20on%20datasets%20with%20scalar%20numbers%2C%20not%20matrices.%20Simple%20solution%3A%20flatten%20the%20matrices%20into%20long%20lists%20during%20encoding%20and%20then%20reshape%20back%20during%20decoding.%0A%20%20%20%203.%20**Data%20scaling.**%20ARC-AGI-2%20uses%20integers%200-9%2C%20but%20our%20encoder%20needs%20values%20in%20%5B0%2C1%5D.%20We%20use%20a%20standard%20MinMaxScaler%20to%20squeeze%20the%20data%20into%20the%20right%20range%20during%20encoding%20and%20unscale%20them%20during%20decoding.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Let's%20take%20it%20step%20by%20step.%20First%2C%20we'll%20treat%20this%20as%20supervised%20learning%20approach%20by%20making%20%60X%60%20the%20question%20input%20and%20%60y%60%20the%20question%20output.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20def%20process_arc_agi(ds)%3A%0A%20%20%20%20%20%20%20%20%23%20only%20look%20at%20public%20eval%20set%0A%20%20%20%20%20%20%20%20split%20%3D%20ds%5B%22eval%22%5D%0A%0A%20%20%20%20%20%20%20%20%23%20Take%20only%20first%20question%20input%2Foutput%20from%20each%20task%0A%20%20%20%20%20%20%20%20question_inputs%20%3D%20%5Btask%5B'question_inputs'%5D%5B0%5D%20for%20task%20in%20split%5D%0A%20%20%20%20%20%20%20%20question_outputs%20%3D%20%5Btask%5B'question_outputs'%5D%5B0%5D%20for%20task%20in%20split%5D%0A%0A%20%20%20%20%20%20%20%20%23%20zero%20pad%20all%20inputs%2Foutputs%20so%20they%20have%20the%20same%20dimension%0A%20%20%20%20%20%20%20%20X%20%3D%20np.zeros((len(question_inputs)%2C%2030%2C%2030))%0A%20%20%20%20%20%20%20%20y%20%3D%20np.zeros((len(question_outputs)%2C%2030%2C%2030))%0A%0A%20%20%20%20%20%20%20%20for%20i%2C%20grid%20in%20enumerate(question_inputs)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20m%2C%20n%20%3D%20len(grid)%2C%20len(grid%5B0%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20X%5Bi%2C%20%3Am%2C%20%3An%5D%20%3D%20grid%0A%0A%20%20%20%20%20%20%20%20for%20i%2C%20grid%20in%20enumerate(question_outputs)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20m%2C%20n%20%3D%20len(grid)%2C%20len(grid%5B0%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20y%5Bi%2C%20%3Am%2C%20%3An%5D%20%3D%20grid%0A%0A%20%20%20%20%20%20%20%20return%20X%2C%20y%0A%20%20%20%20return%20(process_arc_agi%2C)%0A%0A%0A%40app.cell%0Adef%20_(ds%2C%20mo%2C%20process_arc_agi)%3A%0A%20%20%20%20X%2C%20y%20%3D%20process_arc_agi(ds)%0A%20%20%20%20X1%2C%20y1%20%3D%20X%5B%3A1%5D%2C%20y%5B%3A1%5D%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20X%2C%20X1%2C%20y%2C%20y1%0A%0A%0A%40app.cell%0Adef%20_(X1%2C%20mo%2C%20y1)%3A%0A%20%20%20%20print(f'%7BX1.shape%3D%7D%2C%20%7By1.shape%3D%7D')%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X1%2C%20mo%2C%20y1)%3A%0A%20%20%20%20with%20mo.redirect_stdout()%3A%0A%20%20%20%20%20%20%20%20print(f'%7BX1.shape%3D%7D%2C%20%7By1.shape%3D%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X1%2C%20mo)%3A%0A%20%20%20%20print(f'%7BX1%5B0%2C%200%2C%20%3A5%5D%3D%7D')%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X1%2C%20mo)%3A%0A%20%20%20%20with%20mo.redirect_stdout()%3A%0A%20%20%20%20%20%20%20%20print(f'%7BX1%5B0%2C%200%2C%20%3A5%5D%3D%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20y1)%3A%0A%20%20%20%20print(f'%7By1%5B0%2C%200%2C%20%3A5%5D%3D%7D')%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20y1)%3A%0A%20%20%20%20with%20mo.redirect_stdout()%3A%0A%20%20%20%20%20%20%20%20print(f'%7By1%5B0%2C%200%2C%20%3A5%5D%3D%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Second%2C%20we%20transform%20%60y%60%20from%20a%20matrix%20to%20a%20list%20of%20scalars%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20y1)%3A%0A%20%20%20%20y1_flat%20%3D%20y1.flatten()%0A%20%20%20%20print(f'%7By1_flat.shape%3D%7D')%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20(y1_flat%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20y1_flat)%3A%0A%20%20%20%20with%20mo.redirect_stdout()%3A%0A%20%20%20%20%20%20%20%20print(f'%7By1_flat.shape%3D%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22The%20question%20output%20%60y%60%20starts%20out%20as%20a%20%6030x30%60%20matrix%20but%20flattens%20to%20900%20scalar%20elements.%20Crucially%2C%20this%20means%20to%20encode%20a%20single%20ARC-AGI-2%20task%2C%20the%20one-parameter%20model%20must%20encode%20900%20individual%20scalar%20elements%20into%20%24%5Calpha%24.%20Since%20each%20element%20requires%20%24p%24%20bits%20of%20precision%2C%20a%20single%20task%20demands%20%24900p%24%20bits%2C%20not%20just%20%60p%60%20bits.%20This%20cost%20adds%20up%20quickly.%20To%20encode%20all%20400%20tasks%20in%20ARC-AGI-2's%20eval%20set%20into%20one%20%24%5Calpha%24%20requires%20%24400%20%5Ccdot%20900p%3D360%2C000p%24%20bits.%20It%20is%20quite%20easy%20to%20see%20why%20our%20one-parameter%20model%20may%20require%20an%20%24%5Calpha%24%20with%20millions%20of%20bits.%20For%20now%2C%20we'll%20focus%20on%20a%20single%20task%2C%20which%20only%20requires%20%24900p%24%20bits.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Third%2C%20we%20transform%20ARC-AGI-2%20inputs%20from%20%24%5B0%2C%209%5D%24%20to%20%24%5B0%2C%201%5D%24%20with%20the%20MinMaxScaler%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20np)%3A%0A%20%20%20%20class%20MinMaxScaler%3A%0A%20%20%20%20%20%20%20%20def%20__init__(self%2C%20feature_range%3D(1e-10%2C%201-1e-10)%2C%20epsilon%3D1e-10)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20self.min%20%3D%20self.max%20%3D%20self.range%20%3D%20None%0A%20%20%20%20%20%20%20%20%20%20%20%20self.feature_range%2C%20self.epsilon%20%3D%20feature_range%2C%20epsilon%0A%20%20%20%20%20%20%20%20def%20fit(self%2C%20X)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20self.min%2C%20self.max%20%3D%20X.min(axis%3D0)%2C%20X.max(axis%3D0)%0A%20%20%20%20%20%20%20%20%20%20%20%20self.range%20%3D%20np.maximum(self.max%20-%20self.min%2C%20self.epsilon)%20%20%23%20Prevent%20div%20by%20zero%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20self%0A%20%20%20%20%20%20%20%20def%20transform(self%2C%20X)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20X_scaled%20%3D%20(X%20-%20self.min)%20%2F%20self.range%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20np.clip(X_scaled%2C%20*self.feature_range)%20%20%23%20Keep%20away%20from%20exact%20boundaries%0A%20%20%20%20%20%20%20%20def%20fit_transform(self%2C%20X)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20self.fit(X).transform(X)%0A%20%20%20%20%20%20%20%20def%20inverse_transform(self%2C%20X)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20X_clipped%20%3D%20np.clip(X%2C%20*self.feature_range)%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20X_clipped%20*%20self.range%20%2B%20self.min%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20(MinMaxScaler%2C)%0A%0A%0A%40app.cell%0Adef%20_(MinMaxScaler%2C%20mo%2C%20y1_flat)%3A%0A%20%20%20%20scaler%20%3D%20MinMaxScaler()%0A%20%20%20%20y1_scaled%20%3D%20scaler.fit_transform(y1_flat)%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20scaler%2C%20y1_scaled%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20scaler)%3A%0A%20%20%20%20print(f'%7Bscaler.range%3D%7D')%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20scaler)%3A%0A%20%20%20%20with%20mo.redirect_stdout()%3A%0A%20%20%20%20%20%20%20%20print(f'%7Bscaler.range%3D%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20y1_scaled)%3A%0A%20%20%20%20print(f'%7By1_scaled%5B%3A5%5D%3D%7D')%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20y1_scaled)%3A%0A%20%20%20%20with%20mo.redirect_stdout()%3A%0A%20%20%20%20%20%20%20%20print(f'%7By1_scaled%5B%3A5%5D%3D%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Every%20entry%20of%20%60y%60%20is%20in%20the%20proper%20range%2C%20%24%5B0%2C%201%5D%24.%20Remember%2C%20we%20flatten%20and%20scale%20%60y%60%20(question%20output)%20and%20not%20%60X%60%20(question%20input)%20because%20we%20want%20to%20encode%20the%20question%20output%20into%20%24%5Calpha%24.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22We%20are%20ready%20to%20run%20our%20encoder%20and%20learn%20an%20%24%5Calpha%24%20that%20captures%20all%20900%20elements%20in%20the%20first%20ARC-AGI-2%20eval%20task.%20This%20is%20our%20%60model.fit()%60.%20Remember%2C%20this%20is%20%22training%20on%20test%22%20as%20this%20task%20comes%20from%20the%20eval%20set%2C%20not%20the%20train%20set.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(logistic_encoder%2C%20mo%2C%20y1_scaled)%3A%0A%20%20%20%20p%20%3D%207%20%23%20bits%20of%20precision%20for%20a%20single%20sample%0A%20%20%20%20full_precision%20%3D%20len(y1_scaled)%20*%20p%20%23%20bits%20of%20precision%20for%20alpha%20%2F%20all%20samples%20in%20the%20dataset%0A%20%20%20%20alpha%20%3D%20logistic_encoder(y1_scaled%2C%20p%2C%20full_precision)%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20alpha%2C%20full_precision%2C%20p%0A%0A%0A%40app.cell%0Adef%20_(full_precision%2C%20mo)%3A%0A%20%20%20%20print(f'%7Bfull_precision%3D%7D')%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(full_precision%2C%20mo)%3A%0A%20%20%20%20with%20mo.redirect_stdout()%3A%0A%20%20%20%20%20%20%20%20print(f'%7Bfull_precision%3D%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(alpha%2C%20mo)%3A%0A%20%20%20%20print(f'%7Blen(str(alpha))%3D%7D')%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(alpha%2C%20mo)%3A%0A%20%20%20%20with%20mo.redirect_stdout()%3A%0A%20%20%20%20%20%20%20%20print(f'%7Blen(str(alpha))%3D%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22We%20encode%20each%20sample%20with%20%24p%3D7%24%20bits%20of%20precision.%20Alpha%20is%20%241897%24%20decimal%20digits%20long%20and%20%24900%20%5Ccdot%207%20%3D%206300%24%20bits%20long.%20Feel%20free%20to%20scroll%3A%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(alpha%2C%20mo)%3A%0A%20%20%20%20%23%20todo%3A%20show%20alpha%20in%20binary!%0A%20%20%20%20mo.md(f%22%60%60%60py%5Cnalpha%3D%7Bstr(alpha)%7D%5Cn%5Cn%60%60%60%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20This%20single%20%24%5Calpha%24%20encodes%20the%20entire%20task%2C%20all%20900%20individual%20elements%2C%20perfectly.%20This%20is%20our%20one-parameter%20model%20in%20its%20full%20glory.%20All%20we%20need%20is%20this%20alpha%20and%20we%20can%20correctly%20predict%20the%20question%20output%20of%20this%20task.%0A%0A%20%20%20%20To%20decode%20and%20do%20%60model.predict()%60%2C%20we%20must%20run%20our%20decoder%20900%20times%20to%20extract%20all%20900%20invididual%20scalar%20elements%20from%20public%20eval%20task%201%20of%20ARC-AGI-2.%20We%20use%20a%20for%20loop%20for%20this%20in%20%60decode%60.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(alpha%2C%20full_precision%2C%20logistic_decoder%2C%20mo%2C%20np%2C%20p%2C%20tqdm%2C%20y1_scaled)%3A%0A%20%20%20%20def%20decode(alpha%2C%20full_precision%2C%20p%2C%20y_scaled)%3A%0A%20%20%20%20%20%20%20%20return%20np.array(%5Blogistic_decoder(alpha%2C%20full_precision%2C%20p%2C%20i)%20for%20i%20in%20tqdm(range(len(y_scaled))%2C%20total%3Dlen(y_scaled)%2C%20desc%3D%22Decoding%22)%5D)%0A%0A%20%20%20%20y1_pred_%20%3D%20decode(alpha%2C%20full_precision%2C%20p%2C%20y1_scaled)%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20decode%2C%20y1_pred_%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20y1_pred_)%3A%0A%20%20%20%20print(f'%7By1_pred_.shape%3D%7D')%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20y1_pred_)%3A%0A%20%20%20%20with%20mo.redirect_stdout()%3A%0A%20%20%20%20%20%20%20%20print(f'%7By1_pred_.shape%3D%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Now%20let's%20undo%20the%20steps%20from%20before%3A%20reshape%20%60y1_pred_%60%20back%20into%20a%20matrix%20and%20scale%20it%20back%20to%20%60%5B0%2C%209%5D%60.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20scaler%2C%20y1_pred_)%3A%0A%20%20%20%20y1_pred%20%3D%20scaler.inverse_transform(y1_pred_).reshape(1%2C%2030%2C%2030)%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20(y1_pred%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20y1_pred)%3A%0A%20%20%20%20print(f'%7By1_pred.shape%3D%7D')%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20y1_pred)%3A%0A%20%20%20%20with%20mo.redirect_stdout()%3A%0A%20%20%20%20%20%20%20%20print(f'%7By1_pred.shape%3D%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20y1_pred)%3A%0A%20%20%20%20print(f'%7By1_pred%5B0%2C%20%3A5%2C%20%3A5%5D%3D%7D')%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20y1_pred)%3A%0A%20%20%20%20with%20mo.redirect_stdout()%3A%0A%20%20%20%20%20%20%20%20print(f'%7By1_pred%5B%3A%2C%20%3A5%2C%20%3A5%5D%3D%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Great%2C%20now%20the%20output%20of%20the%20decoder%20is%20in%20a%20usual%20form%2C%20%60y1_pred%60.%20Let's%20plot%20the%20results%20to%20see%20how%20well%20our%20one-parameter%20model%20actually%20did%3A%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20plot_matrix%2C%20plt)%3A%0A%20%20%20%20def%20plot_prediction(ds%2C%20split%2C%20i%2C%20predictions%3DNone%2C%20precisions%3DNone%2C%20alpha_n_digits%3DNone%2C%20size%3D2.5%2C%20w%3D0.9%2C%20show_nums%3DFalse)%3A%0A%20%20%20%20%20%20task%20%3D%20ds%5Bsplit%5D%5Bi%5D%0A%20%20%20%20%20%20nq%20%3D%20len(task%5B'question_inputs'%5D)%0A%20%20%20%20%20%20n_pred%20%3D%20len(predictions)%20if%20predictions%20is%20not%20None%20else%200%0A%20%20%20%20%20%20mosaic%20%3D%20%5B%5Bf'Q.%7Bj%2B1%7D_out'%20for%20j%20in%20range(nq)%5D%20%2B%20%5Bf'pred_%7Bk%7D'%20for%20k%20in%20range(n_pred)%5D%5D%0A%20%20%20%20%20%20fig%2C%20axes%20%3D%20plt.subplot_mosaic(mosaic%2C%20figsize%3D(size*(nq%2Bn_pred)%2C%202*size))%0A%20%20%20%20%20%20plt.suptitle(f'ARC-AGI-2%20%7Bsplit.capitalize()%7D%20Task%20%23%7Bi%7D%20(id%3D%7Btask%5B%22id%22%5D%7D)'%2C%20fontsize%3D18%2C%20fontweight%3D'bold'%2C%20y%3D0.98)%0A%0A%20%20%20%20%20%20for%20j%20in%20range(nq)%3A%0A%20%20%20%20%20%20%20%20plot_matrix(task%5B'question_outputs'%5D%5Bj%5D%2C%20axes%5Bf'Q.%7Bj%2B1%7D_out'%5D%2C%20title%3Df%22Q.%7Bj%2B1%7D%20Output%22%2C%20status%3D'predict'%2C%20w%3Dw%2C%20show_nums%3Dshow_nums%20in%20%5BTrue%2C%20'outputs'%5D%20or%20n_pred%20%3E%200)%0A%0A%20%20%20%20%20%20if%20n_pred%3A%0A%20%20%20%20%20%20%20%20if%20precisions%20is%20None%3A%20precisions%20%3D%20%5BNone%5D*n_pred%0A%20%20%20%20%20%20%20%20if%20alpha_n_digits%20is%20None%3A%20alpha_n_digits%20%3D%20%5BNone%5D*n_pred%0A%20%20%20%20%20%20%20%20for%20k%20in%20range(n_pred)%3A%0A%20%20%20%20%20%20%20%20%20%20pred%20%3D%20np.array(predictions%5Bk%5D)%5B%3Alen(task%5B'question_outputs'%5D%5B0%5D)%2C%20%3Alen(task%5B'question_outputs'%5D%5B0%5D%5B0%5D)%5D%0A%20%20%20%20%20%20%20%20%20%20title%20%3D%20%22Q.1%20Prediction%22%0A%20%20%20%20%20%20%20%20%20%20if%20precisions%5Bk%5D%20is%20not%20None%3A%20title%20%3D%20f%22Precision%3D%7Bprecisions%5Bk%5D%7D%5Cn%7Btitle%7D%22%0A%20%20%20%20%20%20%20%20%20%20if%20alpha_n_digits%5Bk%5D%20is%20not%20None%3A%20title%20%3D%20f%22len(%CE%B1)%3D%7Balpha_n_digits%5Bk%5D%7D%20digits%5Cn%7Btitle%7D%22%0A%20%20%20%20%20%20%20%20%20%20plot_matrix(pred%2C%20axes%5Bf'pred_%7Bk%7D'%5D%2C%20title%3Dtitle%2C%20w%3Dw%2C%20show_nums%3DTrue)%0A%20%20%20%20%20%20%20%20fig.add_artist(plt.Line2D(%5Bnq%2F(nq%2Bn_pred)%2C%20nq%2F(nq%2Bn_pred)%5D%2C%20%5B0.05%2C%200.87%5D%2C%20color%3D'%23333333'%2C%20linewidth%3D5%2C%20transform%3Dfig.transFigure))%0A%20%20%20%20%20%20%20%20fig.text(nq%2F(2*(nq%2Bn_pred))%2C%200.91%2C%20'Questions'%2C%20ha%3D'center'%2C%20va%3D'top'%2C%20fontsize%3D13%2C%20fontweight%3D'bold'%2C%20color%3D'%23444444'%2C%20transform%3Dfig.transFigure)%0A%20%20%20%20%20%20%20%20fig.text((nq%2Bn_pred%2F2)%2F(nq%2Bn_pred)%2C%200.91%2C%20'Predictions'%2C%20ha%3D'center'%2C%20va%3D'top'%2C%20fontsize%3D13%2C%20fontweight%3D'bold'%2C%20color%3D'%23444444'%2C%20transform%3Dfig.transFigure)%0A%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20fig.text(0.5%2C%200.91%2C%20'Questions'%2C%20ha%3D'center'%2C%20va%3D'top'%2C%20fontsize%3D13%2C%20fontweight%3D'bold'%2C%20color%3D'%23444444'%2C%20transform%3Dfig.transFigure)%0A%0A%20%20%20%20%20%20fig.patch.set_linewidth(5)%0A%20%20%20%20%20%20fig.patch.set_edgecolor('%23333333')%0A%20%20%20%20%20%20fig.patch.set_facecolor('%23eeeeee')%0A%20%20%20%20%20%20plt.tight_layout(rect%3D%5B0%2C%200%2C%201%2C%200.94%5D%2C%20h_pad%3D1.0)%0A%20%20%20%20%20%20return%20fig%0A%20%20%20%20return%20(plot_prediction%2C)%0A%0A%0A%40app.cell%0Adef%20_(alpha%2C%20ds%2C%20p%2C%20plot_prediction%2C%20y1_pred)%3A%0A%20%20%20%20plot_prediction(ds%2C%20%22eval%22%2C%200%2C%20%5By1_pred.squeeze()%5D%2C%20%5Bp%5D%2C%20%5Blen(str(alpha))%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20The%20left%20column%20shows%20the%20ground%20truth%20(correct%20output)%2C%20while%20the%20right%20column%20displays%20our%20one-parameter%20model's%20prediction.%20We%20don't%20display%20the%20examples%20or%20question%20input%20here.%20We%20adjust%20the%20colors%20to%20reflect%20the%20magnitude%20of%20each%20error%3A%20larger%20deviations%20from%20the%20ground%20truth%20produce%20larger%20differences%20in%20color.%0A%0A%20%20%20%20Look%20at%20the%20first%20row.%20%20The%20correct%20value%20is%207%2C%20and%20we%20predict%206.69.%20The%20next%20cell%20should%20be%207%2C%20and%20we%20predict%206.72.%20The%20third%20cell%20is%209%2C%20and%20we%20predict%208.98.%20Across%20the%20entire%20grid%2C%20our%20predictions%20hover%20near%20the%20correct%20values%2C%20often%20off%20by%20a%20small%20decimal%20amount.%0A%0A%20%20%20%20What%20went%20wrong%3F%0A%0A%20%20%20%20These%20imprecisions%20stem%20from%20our%20choice%20of%20precision%20parameter%20%24p%24.%20Recall%2C%20the%20encoder%20stores%20each%20element%20as%20a%20%24p%24-bit%20number%20and%20discards%20all%20information%20after%20%24p%24%20bits.%20This%20truncation%20introduces%20a%20quantization%20error%20of%20up%20to%20%24%5Cfrac%7B%5Cpi%20R%7D%7B2%5E%7Bp-1%7D%7D%20%3D%200.44%24%20where%20%24p%3D7%24%20is%20the%20precision%20and%20%24R%3D9%24%20is%20the%20range%20of%20the%20MinMaxScaler.%20(Notice%20that%20indeed%20all%20of%20our%20errors%20are%20less%20than%200.44.)%20There%20is%20nothing%20wrong%20with%20our%20encoder%20or%20decoder%3B%20this%20is%20an%20unavoidable%20consequence%20of%20finite-precision%20encoding.%20%0A%0A%20%20%20%20We%20can%2C%20however%2C%20reduce%20the%20error%20by%20increasing%20the%20precision.%20Let's%20test%20this%20with%20%24p%3D14%24.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(decode%2C%20logistic_encoder%2C%20mo%2C%20scaler%2C%20y1_scaled)%3A%0A%20%20%20%20%23%20encode%0A%20%20%20%20y2_scaled%20%3D%20y1_scaled%0A%20%20%20%20p2%20%3D%2014%20%23%20bits%20of%20precision%20for%20a%20single%20sample%0A%20%20%20%20full_precision2%20%3D%20len(y2_scaled)%20*%20p2%20%23%20bits%20of%20precision%20for%20alpha%20%2F%20all%20samples%20in%20the%20dataset%0A%20%20%20%20alpha2%20%3D%20logistic_encoder(y2_scaled%2C%20p2%2C%20full_precision2)%0A%0A%20%20%20%20%23%20decode%0A%20%20%20%20y2_pred_%20%3D%20decode(alpha2%2C%20full_precision2%2C%20p2%2C%20y2_scaled)%0A%20%20%20%20y2_pred%20%3D%20scaler.inverse_transform(y2_pred_).reshape(1%2C%2030%2C%2030)%0A%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20alpha2%2C%20p2%2C%20y2_pred%0A%0A%0A%40app.cell%0Adef%20_(alpha%2C%20alpha2%2C%20ds%2C%20p%2C%20p2%2C%20plot_prediction%2C%20y1_pred%2C%20y2_pred)%3A%0A%20%20%20%20plot_prediction(ds%2C%20%22eval%22%2C%200%2C%20%5By1_pred.squeeze()%2C%20y2_pred.squeeze()%5D%2C%20%5Bp%2C%20p2%5D%2C%20%5Blen(str(alpha))%2C%20len(str(alpha2))%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22When%20%24p%3D14%24%2C%20we%20get%20every%20prediction%20perfectly%20correct%20(up%20to%20two%20decimal%20points).%20However%2C%20this%20comes%20at%20the%20cost%20of%20requiring%20a%20larger%20%24%5Calpha%24%2C%20going%20from%20%246300%24%20digits%20to%20%246504%24%20digits%20or%20in%20binary%2C%20going%20from%20%24900*7%3D63%2C000%24%20bits%20to%20%24900*14%3D12%2C600%24%20bits.%20The%20larger%20%24p%24%20is%2C%20the%20more%20accurately%20our%20encoding%2C%20but%20the%20more%20storage%20it%20takes%20up.%20Still%2C%20this%20is%20a%20pretty%20amazing%20tradeoff!%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20Faster%20Implementation%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20The%20decoder%20works%20great%20for%20a%20single%20task.%20But%20for%20every%20additional%20task%2C%20we%20have%20to%20decode%20another%20900%20elements.%20Decoding%20all%20400%20tasks%20in%20ARC-AGI-2%20would%20take%20hours.%20We%20need%20a%20way%20to%20make%20this%20faster.%20Looking%20at%20our%20current%20decoder%0A%0A%20%20%20%20%60%60%60py%0A%20%20%20%20def%20logistic_decoder(alpha%2C%20full_precision%2C%20p%2C%20i)%3A%0A%20%20%20%20%20%20%20%20mp.prec%20%3D%20full_precision%0A%20%20%20%20%20%20%20%20return%20float(Sin(2%20**%20(i%20*%20p)%20*%20Arcsin(Sqrt(alpha)))%20**%202)%0A%0A%20%20%20%20y2_pred_%20%3D%20np.array(%5Blogistic_decoder(alpha2%2C%20full_precision2%2C%20p2%2C%20i)%20for%20i%20in%20range(len(y2_scaled))%5D)%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20we%20can%20accelerate%20this%20in%20three%20ways%3A%0A%0A%20%20%20%201.%20**Parallelization%3A**%20Because%20each%20element%20is%20decoded%20independently%2C%20we%20can%20decode%20all%20elements%20in%20parallel%20with%20%60multiprocessing.Pool%60.%20This%20speeds%20up%20the%20for%20loop%20over%20%60len(y_scaled))%60.%0A%20%20%20%202.%20**Precomputation%3A**%20Calculate%20%60arcsin(sqrt(alpha))%60%20once%20before%20decoding%20instead%20of%20recomputing%20it%20in%20each%20decoding%20iteration.%20This%20eliminates%20repeated%20expensive%20trigonmetric%20and%20square%20root%20operations.%0A%20%20%20%203.%20**Adaptive%20precision%3A**%20We%20currently%20set%20mpmath's%20precison%20to%20%60full_precision%20%3D%20np%60%20bits%20at%20every%20decoding%20step%2C%20even%20though%20we%20don't%20need%20all%20%24np%24%20bits%20at%20each%20iteration.%20Instead%20we%20can%20use%20%24p(i%2B1)%2B1%24%20bits%20in%20the%20%24i%24th%20decoding%20step%2C%20drastically%20reducing%20the%20number%20of%20bit-operations%20we%20do%20in%20every%20iteration.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20How%20does%20adaptive%20precision%20work%3F%20Why%20can%20we%20use%20%24p(i%2B1)%2B1%24%20bits%20instead%20of%20%24np%24%20bits%20in%20the%20%24i%24th%20decoding%20step%3F%0A%20%20%20%20%20%20%20%20type%3A%20info%0A%0A%20%20%20%20Each%20sample%20is%20encoded%20in%20%24p%24%20bits%2C%20so%20the%20%24i%24th%20sample%20occupies%20bits%20%24ip%24%20through%20%24ip%20%2B%20(p-1)%20%3D%20p(i%2B1)%20-%201%24%20of%20%24%5Calpha%24.%20The%20parts%20of%20%24%5Calpha%24%20beyond%20%24%5Calpha%24%20beyond%20%24p(i%2B1)%20-%201%24%20bits%20are%20irrelevant%20in%20iteration%20%24i%24.%20%0A%0A%20%20%20%20By%20setting%20mpmath's%20precision%20to%20exaclty%20%24p(i%2B1)%20-%201%24%20bits%20in%20iteration%20%24i%24%2C%20we%20perform%20computation%20on%20fewer%20bits%2C%20increasing%20the%20precision%20gradually%3A%20%24p%24%20bits%20in%20iteration%20%240%24%2C%20%242p%24%20bits%20in%20iteration%20%241%24%2C%20and%20so%20on%2C%20up%20to%20%24np%24%20bits%20in%20the%20final%20iteration.%20This%20reduces%20the%20total%20arithmetic%20cost%20from%20%24n%20%5Ccdot%20(np)%24%20bit-operations%20to%0A%0A%20%20%20%20%24%24%0A%20%20%20%20p(1%2B2%2B...%2Bn)%20%3D%20%5Cfrac%7Bn(n%2B1)%7D%7B2%7D%20p%2C%0A%20%20%20%20%24%24%0A%0A%20%20%20%20which%20is%20roughly%202x%20fewer%20arithmetic%20operations.%20Theoretically%20this%20is%20a%20constant%20factor%20improvement.%20However%2C%20in%20practice%20this%20yields%20a%20dramatic%20speedup%20in%20mpmath.%20%0A%0A%20%20%20%20A%20key%20important%20caveat%20is%20that%20this%20optimization%20only%20works%20in%20dyadic%20space%20where%20the%20bit%20structure%20is%20explicit.%20In%20logistic%20space%2C%20the%20bit%20positions%20are%20scrambled%2C%20making%20reduced%20precision%20unusable.%20For%20this%20reason%2C%20we%20apply%20reduced%20precision%20only%20after%20%24%5Cphi%5E%7B-1%7D%24%20transforms%20the%20value%20into%20dyadic%20space.%0A%0A%20%20%20%20Finally%2C%20to%20improve%20numerical%20stability%2C%20we%20set%20mpmath's%20precision%20to%20%24p(i%2B1)%2B1%24%20bits%20--%20two%20bits%20higher%20than%20the%20normal%20%24p(i%2B1)-1%24.%20These%20two%20extra%20bits%20are%20not%20for%20extracting%20additional%20information%20from%20%24%5Calpha%24.%20Instead%2C%20they%20act%20as%20a%20numerical%20buffer%20that%20helps%20preserves%20the%20accuracy%20of%20mpmath%E2%80%99s%20arithmetic.%20Emperically%2C%20we%20need%20this%20otherwise%20mpmath%20does%20not%20work%20properly.%20I'm%20not%20sure%20why...%0A%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Let's%20implement%20these%20three%20speedups%20in%20our%20code.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Sin%2C%20mo%2C%20mp)%3A%0A%20%20%20%20def%20logistic_decoder_fast(arcsin_sqrt_alpha%2C%20p%2C%20i)%3A%0A%20%20%20%20%20%20%20%20mp.prec%20%3D%20p%20*%20(i%20%2B%201)%20%2B%201%0A%20%20%20%20%20%20%20%20return%20float(Sin(2%20**%20(i%20*%20p)%20*%20arcsin_sqrt_alpha)%20**%202)%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22We%20modify%20%60logistic_decoder_fast%60%20to%20take%20in%20%60arcsin_sqrt_alpha%60%20instead%20of%20%24%5Calpha%24%20and%20set%20the%20precision%20to%20%60mp.prec%20%3D%20p%20*%20(i%20%2B%201)%20%2B%201%60%20instead%20of%20%60mp.prec%20%3D%20full_precision%60.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fix_marimo_local_import%2C%20mo)%3A%0A%20%20%20%20%23%20weird%20hack%20for%20html-wasm%20import%20to%20work%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20from%20public.src.model%20import%20fast_decode%0A%20%20%20%20except%20ModuleNotFoundError%3A%0A%20%20%20%20%20%20%20%20fix_marimo_local_import(%22public%2Fsrc%2Fmodel.py%22)%0A%20%20%20%20if%20not%20'fast_decode'%20in%20dir()%20%3A%0A%20%20%20%20%20%20%20%20raise%20ModuleNotFoundError()%0A%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20(fast_decode%2C)%0A%0A%0A%40app.cell%0Adef%20_(display_fxn%2C%20fast_decode%2C%20mo)%3A%0A%20%20%20%20mo.md(rf%22%22%22%7Bdisplay_fxn(fast_decode)%7D%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22We%20parallelize%20the%20decoding%20with%20%60multiprocessing.Pool%60.%20Note%3A%20since%20%60multiprocessing.Pool%60%20%5Bfails%20in%20notebooks%5D(https%3A%2F%2Fbobswinkels.com%2Fposts%2Fmultiprocessing-python-windows-jupyter%2F)%20we%20need%20to%20define%20%60fast_decode%60%20in%20another%20file%20and%20import%20it%20here.%20This%20is%20one%20of%20the%20weird%20quirks%20of%20parallelizing%20operations%20in%20a%20notebook%20and%20why%20%60fast_decode%60%20is%20displayed%20differently%20than%20other%20functions.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Let's%20now%20run%20a%20speed%20test%20and%20compare%20the%20fast%20and%20slow%20decoders%20on%205%20ARC-AGI-2%20tasks%20with%20precision%20%24p%3D7%24.%20First%2C%20we%20encode%20these%205%20tasks%20into%20%24%5Calpha%24%3A%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(MinMaxScaler%2C%20X%2C%20logistic_encoder%2C%20mo%2C%20y)%3A%0A%20%20%20%20%23%20encode%0A%20%20%20%20def%20preprocess(X%2C%20y)%3A%0A%20%20%20%20%20%20%20%20y_flat%20%3D%20y.flatten()%0A%20%20%20%20%20%20%20%20scaler%20%3D%20MinMaxScaler()%0A%20%20%20%20%20%20%20%20y_scaled%20%3D%20scaler.fit_transform(y_flat)%0A%20%20%20%20%20%20%20%20return%20y_scaled%0A%0A%20%20%20%20n_samples%20%3D%205%0A%20%20%20%20y3_scaled%20%3D%20preprocess(X%5B%3An_samples%5D%2C%20y%5B%3An_samples%5D)%20%23%20use%20first%205%20tasks%20of%20ARC-AGI-2%0A%20%20%20%20p3%20%3D%2014%20%23%20bits%20of%20precision%20for%20a%20single%20sample%0A%20%20%20%20full_precision3%20%3D%20len(y3_scaled)%20*%20p3%0A%0A%20%20%20%20alpha3%20%3D%20logistic_encoder(y3_scaled%2C%20p3%2C%20full_precision3)%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20alpha3%2C%20full_precision3%2C%20p3%2C%20y3_scaled%0A%0A%0A%40app.cell%0Adef%20_(alpha3%2C%20mo)%3A%0A%20%20%20%20mo.md(f%22%22%22%60%60%60py%5Cnlenlen(alpha)%3D%7Blen(str(alpha3))%7D%5Cnalpha%3D%7Bstr(alpha3)%7D%5Cn%60%60%60%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Both%20the%20original%20decoder%20and%20the%20fast%20decoder%20use%20the%20same%20%24%5Calpha%24%2C%20which%20has%20543%20digits.%20Now%20let's%20run%20the%20decoders.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(alpha3%2C%20decode%2C%20full_precision3%2C%20mo%2C%20p3%2C%20time%2C%20y3_scaled)%3A%0A%20%20%20%20st%20%3D%20time.perf_counter()%0A%20%20%20%20y3_pred_%20%3D%20decode(alpha3%2C%20full_precision3%2C%20p3%2C%20y3_scaled)%0A%20%20%20%20et%20%3D%20time.perf_counter()%0A%20%20%20%20print(f'Decoding%20Took%20%7Bet-st%7D%20secs')%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20et%2C%20st%2C%20y3_pred_%0A%0A%0A%40app.cell%0Adef%20_(et%2C%20mo%2C%20st)%3A%0A%20%20%20%20with%20mo.redirect_stdout()%3A%0A%20%20%20%20%20%20%20%20print(f'Decoding%20Took%20%7Bet-st%7D%20secs')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(alpha3%2C%20fast_decode%2C%20p3%2C%20time%2C%20y3_scaled)%3A%0A%20%20%20%20st_fast%20%3D%20time.perf_counter()%0A%20%20%20%20y3_pred_fast_%20%3D%20fast_decode(alpha3%2C%20p3%2C%20y3_scaled)%0A%20%20%20%20et_fast%20%3D%20time.perf_counter()%0A%20%20%20%20print(f'Fast%20Decoding%20Took%20%7Bet_fast-st_fast%7D%20secs')%0A%20%20%20%20return%20et_fast%2C%20st_fast%2C%20y3_pred_fast_%0A%0A%0A%40app.cell%0Adef%20_(et_fast%2C%20mo%2C%20st_fast)%3A%0A%20%20%20%20with%20mo.redirect_stdout()%3A%0A%20%20%20%20%20%20%20%20print(f'Fast%20Decoding%20Took%20%7Bet_fast-st_fast%7D%20secs')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20The%20original%20decoder%20runs%20in%2035.6%20seconds%20and%20the%20fast%20decoder%20in%202.7%20seconds.%20This%20is%20a%2013x%20speedup%20on%20my%20Mac%20M1%20Pro!%20Since%20we%20encode%205%20tasks%2C%20each%20with%20900%20samples%2C%20we've%20decoded%20a%20total%20of%20%245%20%5Ccdot%20900%3D4500%24%20individual%20tasks.%0A%0A%20%20%20%20Due%20to%20adaptive%20precision%2C%20the%20fast%20decoder%20may%20produce%20slightly%20different%20values%20after%20the%20first%20%24p%24%20bits%20compared%20to%20the%20regular%20decoder.%20We%20verify%20that%20both%20decoders%20remain%20within%20the%20theoretical%20error%20tolerance%20of%20each%20other.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20p3%2C%20y3_pred_%2C%20y3_pred_fast_)%3A%0A%20%20%20%20tol%20%3D%20np.pi%2F2**(p3-1)%0A%20%20%20%20np.testing.assert_allclose(y3_pred_%2C%20y3_pred_fast_%2C%20atol%3Dtol)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22This%20is%20great!%20We%20now%20have%20a%20fast%20decoder%20implementation%20that%20can%20handle%20multiple%20tasks!%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20Final%20Implementation%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22We%20are%20now%20ready%20to%20create%20the%20final%20implementation%20of%20the%20one-parameter%20model.%20(Again%2C%20because%20%60multiprocessing.Pool%60%20fails%20in%20notebooks%20we%20define%20%60OneParameterModel%60%20in%20another%20file%20and%20import%20it%20here.)%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fix_marimo_local_import%2C%20mo)%3A%0A%20%20%20%20%23%20weird%20hack%20for%20html-wasm%20import%20to%20work%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20from%20public.src.model%20import%20OneParameterModel%0A%20%20%20%20except%20ModuleNotFoundError%3A%0A%20%20%20%20%20%20%20%20fix_marimo_local_import(%22public%2Fsrc%2Fmodel.py%22)%0A%0A%20%20%20%20if%20not%20'OneParameterModel'%20in%20dir()%20%3A%0A%20%20%20%20%20%20%20%20raise%20ModuleNotFoundError()%0A%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20(OneParameterModel%2C)%0A%0A%0A%40app.cell%0Adef%20_(OneParameterModel%2C%20display_fxn%2C%20mo)%3A%0A%20%20%20%20mo.md(rf%22%22%22%7Bdisplay_fxn(OneParameterModel)%7D%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20The%20code%20is%20quite%20simple%20and%20looks%20like%20a%20standard%20scikit-learn%20ML%20model%3A%0A%0A%20%20%20%20*%20%60model.fit%60%20runs%20the%20encoder.%20It%20also%20scales%20and%20reshapes%20the%20data.%0A%20%20%20%20*%20%60model.predict%60%20runs%20the%20(fast)%20decoder.%20It%20runs%20the%20decoder%20in%20parallel%20and%20reverses%20the%20data%20scaling%2C%20reshaping.%0A%20%20%20%20*%20%60model.verfiy%60%20checks%20that%20the%20outputted%20predictions%20are%20within%20the%20theoretical%20error%20bounds%20we%20derived.%0A%0A%20%20%20%20The%20one-parameter%20model%20is%20quite%20elegant.%20%60OneParameterModel%60%20itself%20is%20~50%20lines%20of%20code%20and%20the%20math%20functions%20it%20uses%20are%20probably%20another%20~50%20lines%20of%20code%20(%60phi%60%2C%20%60phi_inverse%60%2C%20%60decimal_to_binary%60%2C%20%60binary_to_decimal%60%2C%20%60logistic_encoder%60%2C%20and%20%60logistic_decoder%60).%20Only%20around%20100%20lines%20to%20get%20a%20perfect%20score%20on%20ARC-AGI-2!%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(OneParameterModel%2C%20X%2C%20y)%3A%0A%20%20%20%20p4%20%3D%204%0A%20%20%20%20model%20%3D%20OneParameterModel(p4)%0A%20%20%20%20model.fit(X%2C%20y)%0A%20%20%20%20return%20(model%2C)%0A%0A%0A%40app.cell%0Adef%20_(model%2C%20np)%3A%0A%20%20%20%20idx%20%3D%202%0A%20%20%20%20y4_pred%20%3D%20model.predict(np.array(%5Bidx%2C%20idx%2B1%5D))%0A%20%20%20%20return%20idx%2C%20y4_pred%0A%0A%0A%40app.cell%0Adef%20_(idx%2C%20model%2C%20np%2C%20y%2C%20y4_pred)%3A%0A%20%20%20%20model.verify(y4_pred%2C%20y%5Bnp.array(%5Bidx%2C%20idx%2B1%5D)%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20OneParameterModel%2C%0A%20%20%20%20X%2C%0A%20%20%20%20ds%2C%0A%20%20%20%20functools%2C%0A%20%20%20%20np%2C%0A%20%20%20%20plot_arcagi%2C%0A%20%20%20%20plt%2C%0A%20%20%20%20process_arc_agi%2C%0A%20%20%20%20y%2C%0A)%3A%0A%20%20%20%20%40functools.cache%20%23%20pylint%3A%20disable%3Dmethod-cache-max-size-none%0A%20%20%20%20def%20cached_fit(p)%3A%0A%20%20%20%20%20%20%20%20model%20%3D%20OneParameterModel(p)%0A%20%20%20%20%20%20%20%20model.fit(X%2C%20y)%0A%20%20%20%20%20%20%20%20return%20model%0A%0A%20%20%20%20%40functools.cache%20%23%20pylint%3A%20disable%3Dmethod-cache-max-size-none%0A%20%20%20%20def%20run(idx%2C%20p)%3A%0A%20%20%20%20%20%20%20%20X%2C%20y%20%3D%20process_arc_agi(ds)%0A%20%20%20%20%20%20%20%20model%20%3D%20cached_fit(p)%0A%20%20%20%20%20%20%20%20y_pred%20%3D%20model.predict(np.array(%5Bidx%5D))%0A%20%20%20%20%20%20%20%20model.verify(y_pred%2C%20y%5Bnp.array(%5Bidx%5D)%5D)%0A%20%20%20%20%20%20%20%20plot_arcagi(ds%2C%20%22eval%22%2C%20idx%2C%20y_pred%2C%20show_nums%3DFalse)%0A%20%20%20%20%20%20%20%20plt.show()%0A%20%20%20%20%20%20%20%20print(f%22p%3D%7Bp%7D%5Cnalpha%3D%7Bstr(model.alpha)%5B%3A10_000%5D%7D%22)%0A%20%20%20%20return%20(run%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20precision_slider%20%3D%20mo.ui.slider(start%3D1%2C%20stop%3D10%2C%20step%3D1%2C%20show_value%3DTrue%2C%20label%3D%22Precision%22)%0A%20%20%20%20precision_slider%0A%20%20%20%20return%20(precision_slider%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20idx_slider%20%3D%20mo.ui.slider(start%3D1%2C%20stop%3D10%2C%20step%3D1%2C%20show_value%3DTrue%2C%20label%3D%22Sample%22)%0A%20%20%20%20idx_slider%0A%20%20%20%20return%20(idx_slider%2C)%0A%0A%0A%40app.cell%0Adef%20_(idx_slider%2C%20precision_slider%2C%20run)%3A%0A%20%20%20%20run(idx_slider.value%2C%20precision_slider.value)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20Conclusion%0A%0A%20%20%20%20%3E%20%22With%20four%20parameters%20I%20can%20fit%20an%20elephant%2C%20and%20with%20five%20I%20can%20make%20him%20wiggle%20his%20trunk.%22%20-%20John%20von%20Neumann%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20Other%20uses%20for%20the%20one-parameter%20model%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20We've%20built%20a%20model%20that%20achieves%20100%25%20on%20ARC-AGI-2%20with%20one%20parameter.%20Indeed%2C%20this%20technique%20is%20quite%20powerful%20and%20can%20be%20applied%20to%20tons%20of%20other%20datasets%2C%20achieving%20perfect%20accuracy%20every%20time.%0A%0A%20%20%20%20For%20instance%2C%20we%20can%20encode%20animal%20shapes%20with%20different%20values%20of%20%24%5Calpha%24%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fix_marimo_path%2C%20mo)%3A%0A%20%20%20%20animals_image%20%3D%20mo.image(%0A%20%20%20%20%20%20%20%20fix_marimo_path(%22public%2Fimages%2Fanimals.png%22)%2C%0A%20%20%20%20%20%20%20%20width%3D800%2C%0A%20%20%20%20%20%20%20%20caption%3D%22Encode%20animals%20with%20different%20values%20of%20alpha.%20Figure%201%20of%20'Real%20numbers%2C%20data%20science%20and%20chaos%3A%20How%20to%20fit%20any%20dataset%20with%20a%20single%20parameter'.%22%2C%0A%20%20%20%20%20%20%20%20style%3D%7B%22display%22%3A%20%22block%22%2C%20%22margin%22%3A%20%220%20auto%22%7D%0A%20%20%20%20)%0A%20%20%20%20animals_image%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20We%20can%20find%20an%20%24%5Calpha%24%20that%20perfectly%20predicts%20the%20fluctuations%20of%20the%20S%26P%20500%20for%20~6%20months%20with%0A%20%20%20%20%60%60%60py%0A%20%20%20%20alpha%20%3D%200.9186525008673170697061215177743819472103574383504939864690954692792184358812098296063847317394708021665491910117472119056871470143410398692872752461892785029829514157709738923288994766865216570536672099485574178884250989741343121%0A%20%20%20%20%60%60%60%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fix_marimo_path%2C%20mo)%3A%0A%20%20%20%20stocks_image%20%3D%20mo.image(%0A%20%20%20%20%20%20%20%20fix_marimo_path(%22public%2Fimages%2Fs_and_p.png%22)%2C%0A%20%20%20%20%20%20%20%20width%3D800%2C%0A%20%20%20%20%20%20%20%20caption%3D%22Predict%20the%20S%26P%20500%20with%20100%25%20accuracy%20until%20mid%20Febuary%202019.%20From%20Figure%209%20of%20'Real%20numbers%2C%20data%20science%20and%20chaos%3A%20How%20to%20fit%20any%20dataset%20with%20a%20single%20parameter'.%22%2C%0A%20%20%20%20%20%20%20%20style%3D%7B%22display%22%3A%20%22block%22%2C%20%22margin%22%3A%20%220%20auto%22%7D%0A%20%20%20%20)%0A%20%20%20%20stocks_image%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22And%20we%20can%20even%20find%20values%20of%20%24%5Calpha%24%20that%20generate%20parts%20of%20the%20famous%20%5BCIFAR-10%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FCIFAR-10)%20dataset%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fix_marimo_path%2C%20mo)%3A%0A%20%20%20%20cifar10_image%20%3D%20mo.image(%0A%20%20%20%20%20%20%20%20fix_marimo_path(%22public%2Fimages%2Fcifar_10.png%22)%2C%0A%20%20%20%20%20%20%20%20width%3D800%2C%0A%20%20%20%20%20%20%20%20caption%3D%22Encode%20samples%20that%20look%20like%20they%20are%20from%20cifar-10.%20From%20Figure%203%20of%20'Real%20numbers%2C%20data%20science%20and%20chaos%3A%20How%20to%20fit%20any%20dataset%20with%20a%20single%20parameter'.%22%2C%0A%20%20%20%20%20%20%20%20style%3D%7B%22display%22%3A%20%22block%22%2C%20%22margin%22%3A%20%220%20auto%22%7D%0A%20%20%20%20)%0A%20%20%20%20cifar10_image%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22This%20technique%20is%20incredibly%20verstile%2C%20able%20to%20achieve%20perfect%20acuracy%20across%20tons%20of%20different%20domains.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20To%20the%20critics%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20Yet%20at%20the%20same%20time%2C%20the%20one-parameter%20model%20is%20incredibly%20brittle.%20It%20exists%20as%20a%20crude%20hack%2C%20directly%20encoding%20the%20train%20set%20into%20a%20single%20parameter.%20Even%20simply%20shuffling%20the%20dataset%20will%20cause%20your%20model%20to%20break%20down.%20The%20decoder%20depends%20on%20the%20index%20%24i%24%2C%20not%20the%20sample%20%24x_i%24.%20It%20should%20be%20abundantly%20clear%20that%20the%20one-parameter%20model%20has%20no%20ability%20to%20generalize%20whatsoever.%20It%20would%20get%20a%200%25%20on%20the%20private%2C%20heldout%20test%20set%20of%20ARCI-AGI-2.%0A%0A%20%20%20%20Two%20quick%20technical%20notes%20to%20the%20critics.%0A%0A%20%20%20%20**For%20the%20complexity%20theorists**%2C%20yes%2C%20this%20is%20cheating.%20We've%20violated%20the%20fundamental%20assumption%20of%20bounded-precision%20arithmetic.%20Most%20complexity%20problems%20assume%20we%20operate%20on%20a%20machine%20with%20an%20%24%5Comega%24-bit%20word-size.%20However%2C%20my%20one-parameter%20model%20assumes%20we%20can%20operate%20on%20a%20machine%20with%20infinite%20bit%20word-size.%0A%0A%20%20%20%20**For%20the%20deep%20learning%20theorists**%2C%20of%20course%20our%20one-parameter%20model%20can%20memorize%20any%20dataset.%20Our%20decoder%20contains%20%24%5Csin%24%20which%20has%20an%20%5Binfinite%20VC%20dimension%5D(https%3A%2F%2Fcseweb.ucsd.edu%2Fclasses%2Ffa12%2Fcse291-b%2Fvcnotes.pdf)%2C%20i.e.%20an%20unbounded%20hypothesis%20class%2C%20and%20is%20therefore%20infinitely%20expressive.%20It%20can%20learn%20anything.%20What%20is%20interesting%20about%20the%20one-parameter%20model%20is%20that%20it%20offers%20a%20tangible%20construction%2C%20not%20merely%20a%20claim%20of%20existence%2C%20for%20learning%20any%20dataset.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20Lessons%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20A%20couple%20of%20key%20takeaways%20here.%0A%0A%20%20%20%20**Intelligence%20is%20not%20parameter%20count.**%0A%0A%20%20%20%20The%20existence%20of%20such%20a%20simple%20equation%0A%0A%20%20%20%20%24%24%0A%20%20%20%20f_%7B%5Calpha%2C%20p%7D(i)%0A%20%20%20%20%3D%0A%20%20%20%20%5Csin%5E2%20%5CBig(%0A%20%20%20%20%20%20%20%202%5E%7Bi%20p%7D%20%5Carcsin(%5Csqrt%7B%5Calpha%7D)%0A%20%20%20%20%5CBig)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20with%20such%20powerful%20expressivity%20deomonstrates%20that%20model%20complexity%20cannot%20be%20determined%20by%20counting%20parameters%20alone.%20The%20one-parameter%20model%20exploits%20a%20often-overlooked%20fact%3A%20a%20single%20real-valued%20parameter%20can%20encode%20an%20unbounded%20amount%20of%20information%20by%20hiding%20complexity%20in%20its%20digits%20rather%20than%20in%20parameter%20count.%20In%20other%20words%2C%20don't%20automatically%20assume%20that%20a%20bigger%20model%20is%20a%20smarter%20model.%20Parameter%20count%20can%20be%20a%20poor%20proxy%20for%20intelligence.%0A%0A%20%20%20%20**Intelligence%20is%20compression.**%0A%0A%20%20%20%20To%20compress%20data%2C%20you%20must%20find%20regularities%20in%20it%20and%20finding%20regularities%20fundamentally%20requires%20intelligent%20pattern%20matching.%20If%20%5Bintelligence%20is%20compression%5D((https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FHutter_Prize))%2C%20then%20our%20one-parameter%20model%20has%20all%20the%20intelligence%20of%20a%20phonebook.%20It%20achieves%20zero%20compression%20and%20is%20just%20a%20nice%20lookup%20table.%20It%20cannot%20discover%20patterns%20or%20extract%20structure.%20The%20one-parameter%20model%20simply%20stores%20the%20raw%20data%20and%20uses%20the%20precision%20%24p%24%20as%20a%20tunable%20recovery%20knob.%0A%0A%20%20%20%20Real%20compression%20requires%20understanding.%20If%20you%20want%20to%20measure%20the%20complexity%20and%20expressivity%20of%20machine%20learning%20models%2C%20measure%20their%20compression.%20Use%20minimum%20description%20length%20or%20Kolmogorov%20complexity.%20These%20techniques%20capture%20whether%20a%20model%20has%20actually%20learned%20the%20underlying%20patterns.%20They%20cut%20through%20the%20illusion%20of%20parameter%20counts%20and%20reveal%20what%20the%20model%20truly%20understands.%0A%0A%20%20%20%20Prof.%20Albert%20Gu's%20paper%20%5BARC-AGI%20without%20pretraining%5D(https%3A%2F%2Filiao2345.github.io%2Fblog_posts%2Farc_agi_without_pretraining%2Farc_agi_without_pretraining.html)%20actually%20does%20this%20right.%20They%20used%20a%20general-purpose%20compression%20algorithm%20to%20solve%20ARC-AGI%20without%20training%20on%20the%20test%20set.%20That's%20the%20real%20deal.%20Our%20one-parameter%20model%20is%20a%20degenerate%20version%20of%20the%20same%20idea.%0A%0A%20%20%20%20**Training%20on%20Test**%0A%0A%20%20%20%20Our%20one-parameter%20model%20takes%20the%20idea%20of%20%22training%20on%20test%22%20to%20the%20extreme%3A%20it%20encodes%20the%20entire%20test%20set%20directly%20into%20%24%5Calpha%24%2C%20achieving%20100%25%20accuracy%20while%20learning%20nothing.%20The%20one-parameter%20model%20is%20utterly%20impractical%20and%2C%20frankly%2C%20an%20absurd%20hack.%20But%20that's%20precisely%20the%20point%3A%20it%20is%20absurd%20to%20train%20on%20the%20test%20set%20just%20to%20get%20to%20the%20top%20of%20a%20leaderboard.%0A%0A%20%20%20%20Yet%20this%20is%20exactly%20what%20occurs%20in%20the%20AI%20community.%0A%0A%20%20%20%20Top%20AI%20labs%20quietly%20train%20on%20their%20test%20sets.%20The%20one-parameter%20model%20does%20it%20proudly.%0A%0A%20%20%20%20It%20is%20rumoured%20these%20labs%20have%20entire%20teams%20who%20generate%20synthetic%20dataset%20for%20the%20sole%20purpose%20of%20succeeding%20on%20a%20specific%20benchmark.%20This%20is%20overfitting%20taken%20to%20the%20extreme.%0A%0A%20%20%20%20**The%20ARC-AGI%20Benchmark**%0A%0A%20%20%20%20ARC-AGI%20was%20intentionally%20designed%20to%20resist%20overfitting.%20It%20uses%20a%20private%20test%20set%20for%20official%20scoring%2C%20making%20training%20on%20test%20impossible.%20(Our%20one-parameter%20model%20only%20trained%20on%20the%20public%20eval%20set.)%20Yet%20even%20ARC-AGI's%20organizers%20have%20raised%20concerns%20about%20test%20contamination%20creeping%20into%20modern%20AI%20development.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fix_marimo_path%2C%20mo)%3A%0A%20%20%20%20arc_agi_overfitting_image%20%3D%20mo.image(%0A%20%20%20%20%20%20%20%20fix_marimo_path(%22public%2Fimages%2Farc_agi_overfitting.png%22)%2C%0A%20%20%20%20%20%20%20%20width%3D800%2C%0A%20%20%20%20%20%20%20%20caption%3D%22Mike%20Knoop%20on%20ARC-AGI%20overfitting.%20Retreived%20from%20https%3A%2F%2Farcprize.org%2Fblog%2Farc-prize-2025-results-analysis%20on%20December%209th%2C%202025.%22%2C%0A%20%20%20%20%20%20%20%20style%3D%7B%22display%22%3A%20%22block%22%2C%20%22margin%22%3A%20%220%20auto%22%7D%0A%20%20%20%20)%0A%20%20%20%20arc_agi_overfitting_image%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20Yet%20there%20is%20a%20more%20fundamental%20point%3A%20many%20of%20the%20amazing%20approaches%20to%20the%20ARC-AGI%20competition%20seem%20to%20overfit%20to%20ARC-AGI%20itself.%20Researchers%20generate%20synthetic%20data%20specific%20to%20ARC-AGI%20and%20create%20abstractions%20unique%20to%20the%20grid%20structure%20of%20the%20competition.%20I%20doubht%20many%20of%20their%20techniques%20would%20generalize%20to%20other%20reasoning%20problems.%20How%20many%20of%20the%20innovative%20solutions%20to%20ARC-AGI%20have%20inspired%20downstream%20improvements%20in%20LLMs%20or%20other%20modes%20of%20intelligence%3F%20I%20hope%20these%20techniques%20prove%20to%20be%20good%20for%20more%20than%20just%20ARC-AGI's%20delightful%20puzzles%20and%20drive%20broader%20innovation%20the%20field%20of%20AI.%0A%0A%20%20%20%20**Final%20Thoughts**%0A%0A%20%20%20%20To%20close%2C%20I%E2%80%99ll%20return%20to%20the%20line%20we%20began%20with%3A%0A%0A%20%20%20%20%3E%20%22When%20a%20measure%20becomes%20a%20target%2C%20it%20ceases%20to%20be%20a%20good%20measure%22%20-%20Charles%20Goodhart%0A%0A%20%20%20%20Indeed%2C%20the%20one-parameter%20model%20serves%20as%20a%20*reductio%20ad%20absurdum*%20of%20what%20happens%20when%20metrics%20become%20the%20goal%20rather%20than%20the%20guide.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20If%20you%20liked%20this%20or%20want%20to%20chat%2C%20reach%20out!%20I%20always%20love%20talking%20to%20people%20working%20in%20interesting%20problems.%0A%0A%20%20%20%20To%20cite%20this%20blog%20post%0A%20%20%20%20%60%60%60md%0A%20%20%20%20%40online%7BTurok2025ARCAGI%2C%0A%20%20%20%20%09author%20%3D%20%7BEthan%20Turok%7D%2C%0A%20%20%20%20%09title%20%3D%20%7BI%20built%20a%20one-parameter%20model%20that%20gets%20100%25%20on%20ARC-AGI-2%7D%2C%0A%20%20%20%20%09year%20%3D%20%7B2025%7D%2C%0A%20%20%20%20%09url%20%3D%20%7Bhttps%3A%2F%2Feitanturok.github.io%2Fone-parameter-model%2F%7D%2C%0A%20%20%20%20%7D%0A%20%20%20%20%60%60%60%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
b8358ab50a6c61fe1f76e30b84692a919b4bfed026654c9f57e183dfdd7ec467